RAVE-978 - Added getAll method for Users/People - Added basic authentication to support web service calls - Added a webservice itest framework - Added simple people webservice itest for getting all users
Project: http://git-wip-us.apache.org/repos/asf/rave/repo Commit: http://git-wip-us.apache.org/repos/asf/rave/commit/b7cd8dea Tree: http://git-wip-us.apache.org/repos/asf/rave/tree/b7cd8dea Diff: http://git-wip-us.apache.org/repos/asf/rave/diff/b7cd8dea Branch: refs/heads/angular Commit: b7cd8deaee9d88d602a8f1fe7870d28038fc3ac9 Parents: 18d5ae2 Author: Chris Geer <[email protected]> Authored: Sun Jul 6 14:26:35 2014 -0700 Committer: Chris Geer <[email protected]> Committed: Sun Jul 6 14:26:35 2014 -0700 ---------------------------------------------------------------------- .../rave/rest/model/JsonResponseWrapper.java | 11 +- .../java/org/apache/rave/rest/model/Person.java | 97 +++++++++++++- .../portal/repository/PersonRepository.java | 8 ++ .../apache/rave/portal/service/UserService.java | 7 + .../portal/service/impl/DefaultUserService.java | 5 + .../service/impl/DefaultUserServiceTest.java | 8 ++ rave-integration-tests/pom.xml | 27 +++- .../rave-webservice-tests/pom.xml | 128 +++++++++++++++++++ .../webservice/StateManager.java | 37 ++++++ .../integrationtests/webservice/Stories.java | 101 +++++++++++++++ .../webservice/steps/CommonSteps.java | 63 +++++++++ .../webservice/steps/PeopleSteps.java | 122 ++++++++++++++++++ .../integrationtests/webservice/people.story | 40 ++++++ .../WEB-INF/applicationContext-security.xml | 1 + 14 files changed, 640 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/rave/blob/b7cd8dea/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/JsonResponseWrapper.java ---------------------------------------------------------------------- diff --git a/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/JsonResponseWrapper.java b/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/JsonResponseWrapper.java index ec2fe08..c2efb69 100644 --- a/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/JsonResponseWrapper.java +++ b/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/JsonResponseWrapper.java @@ -22,18 +22,15 @@ package org.apache.rave.rest.model; import java.util.HashMap; import java.util.List; -/** - * Created with IntelliJ IDEA. - * User: erinnp - * Date: 7/19/13 - * Time: 11:37 AM - * To change this template use File | Settings | File Templates. - */ public class JsonResponseWrapper { private HashMap<String, String> metadata; private Object data; + public JsonResponseWrapper() { + + } + public JsonResponseWrapper(SearchResult searchResult) { this.metadata = new HashMap<String, String>(); this.data = searchResult.getResultSet(); http://git-wip-us.apache.org/repos/asf/rave/blob/b7cd8dea/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/Person.java ---------------------------------------------------------------------- diff --git a/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/Person.java b/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/Person.java index 1820647..e91b7a2 100644 --- a/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/Person.java +++ b/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/Person.java @@ -35,12 +35,36 @@ public class Person implements RestEntity{ private String displayName; @XmlElement(name = "EmailAddress") private String emailAddress; + @XmlElement(name = "AboutMe") + private String aboutMe; + @XmlElement(name = "PreferredName") + private String preferredName; + @XmlElement(name = "Status") + private String status; + @XmlElement(name = "AdditionalName") + private String additionalName; + @XmlElement(name = "FamilyName") + private String familyName; + @XmlElement(name = "GivenName") + private String givenName; + @XmlElement(name = "HonorificPrefix") + private String honorificPrefix; + @XmlElement(name = "HonorificSuffix") + private String honorificSuffix; public Person(org.apache.rave.model.Person person) { id = person.getId(); username = person.getUsername(); displayName = person.getDisplayName(); emailAddress = person.getEmail(); + aboutMe = person.getAboutMe(); + preferredName = person.getPreferredName(); + status = person.getStatus(); + additionalName = person.getAdditionalName(); + familyName = person.getFamilyName(); + givenName = person.getGivenName(); + honorificPrefix = person.getHonorificPrefix(); + honorificSuffix = person.getHonorificSuffix(); } public Person() { @@ -78,6 +102,70 @@ public class Person implements RestEntity{ this.emailAddress = emailAddress; } + public String getAboutMe() { + return aboutMe; + } + + public void setAboutMe(String aboutMe) { + this.aboutMe = aboutMe; + } + + public String getPreferredName() { + return preferredName; + } + + public void setPreferredName(String preferredName) { + this.preferredName = preferredName; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getAdditionalName() { + return additionalName; + } + + public void setAdditionalName(String additionalName) { + this.additionalName = additionalName; + } + + public String getFamilyName() { + return familyName; + } + + public void setFamilyName(String familyName) { + this.familyName = familyName; + } + + public String getGivenName() { + return givenName; + } + + public void setGivenName(String givenName) { + this.givenName = givenName; + } + + public String getHonorificPrefix() { + return honorificPrefix; + } + + public void setHonorificPrefix(String honorificPrefix) { + this.honorificPrefix = honorificPrefix; + } + + public String getHonorificSuffix() { + return honorificSuffix; + } + + public void setHonorificSuffix(String honorificSuffix) { + this.honorificSuffix = honorificSuffix; + } + public void saveToPerson(org.apache.rave.model.Person person) { if (person.getId() != null && !person.getId().equals(id)) { throw new RuntimeException("You cannot change the ID of a Person object"); @@ -86,6 +174,13 @@ public class Person implements RestEntity{ if (username != null) { person.setUsername(username); } if (displayName != null) { person.setDisplayName(displayName); } if (emailAddress != null) { person.setEmail(emailAddress); } + if (aboutMe != null) { person.setAboutMe(aboutMe); } + if (preferredName != null) { person.setPreferredName(preferredName); } + if (additionalName != null) { person.setAdditionalName(additionalName); } + if (familyName != null) { person.setFamilyName(familyName); } + if (givenName != null) { person.setGivenName(givenName); } + if (honorificPrefix != null) { person.setHonorificPrefix(honorificPrefix); } + if (honorificSuffix != null) { person.setHonorificSuffix(honorificSuffix); } + if (status != null) { person.setStatus(status); } } - } http://git-wip-us.apache.org/repos/asf/rave/blob/b7cd8dea/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/PersonRepository.java ---------------------------------------------------------------------- diff --git a/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/PersonRepository.java b/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/PersonRepository.java index 176c2ed..e81ecc2 100644 --- a/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/PersonRepository.java +++ b/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/PersonRepository.java @@ -28,6 +28,14 @@ import org.apache.rave.model.Person; public interface PersonRepository extends Repository<Person> { + + /** + * Gets a list of all the people + * + * @return + */ + List<Person> getAll(); + /** * Gets a user by their username * http://git-wip-us.apache.org/repos/asf/rave/blob/b7cd8dea/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/UserService.java ---------------------------------------------------------------------- diff --git a/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/UserService.java b/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/UserService.java index 9f2df7d..b0bacbc 100644 --- a/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/UserService.java +++ b/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/UserService.java @@ -235,4 +235,11 @@ public interface UserService extends UserDetailsService, AuthenticationUserDetai */ SearchResult<Person> getPersonsByFreeTextSearch(String searchTerm, int offset, int pageSize); + /** + * Gets the {@link Person} list containing all the people + * + * @return + */ + List<Person> getAllPeople(); + } http://git-wip-us.apache.org/repos/asf/rave/blob/b7cd8dea/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java ---------------------------------------------------------------------- diff --git a/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java b/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java index 3b4f520..fd25291 100644 --- a/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java +++ b/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java @@ -280,6 +280,11 @@ public class DefaultUserService implements UserService { } @Override + public List<Person> getAllPeople() { + return personRepository.getAll(); + } + + @Override @Transactional // TODO RAVE-300: add security check that is is called by admin or the user itself public void deleteUser(String userId) { http://git-wip-us.apache.org/repos/asf/rave/blob/b7cd8dea/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java ---------------------------------------------------------------------- diff --git a/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java b/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java index 4080022..053ea3f 100644 --- a/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java +++ b/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java @@ -393,4 +393,12 @@ public class DefaultUserServiceTest { service.registerNewUser(user); verify(userRepository, pageTemplateRepository, pageRepository); } + + @Test + public void getAllPeople() { + expect(personRepository.getAll()).andReturn(new ArrayList<Person>()); + replay(personRepository); + service.getAllPeople(); + verify(personRepository); + } } http://git-wip-us.apache.org/repos/asf/rave/blob/b7cd8dea/rave-integration-tests/pom.xml ---------------------------------------------------------------------- diff --git a/rave-integration-tests/pom.xml b/rave-integration-tests/pom.xml index 2552328..24b2859 100644 --- a/rave-integration-tests/pom.xml +++ b/rave-integration-tests/pom.xml @@ -216,7 +216,7 @@ </includes> <excludes /> <generateViewAfterStories>true</generateViewAfterStories> - <ignoreFailureInStories>true</ignoreFailureInStories> + <ignoreFailureInStories>false</ignoreFailureInStories> <ignoreFailureInView>true</ignoreFailureInView> <metaFilters> <metaFilter>${meta.filter}</metaFilter> @@ -233,6 +233,19 @@ </build> <profiles> <profile> + <id>default</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <modules> + <module>rave-webservice-tests</module> + <module>rave-core-tests</module> + <module>rave-newuser-tests</module> + <module>rave-admin-tests</module> + <module>rave-default-account-tests</module> + </modules> + </profile> + <profile> <id>integration-tests</id> <build> <defaultGoal>integration-test</defaultGoal> @@ -374,11 +387,11 @@ </plugins> </build> </profile> + <profile> + <id>webservice</id> + <modules> + <module>rave-webservice-tests</module> + </modules> + </profile> </profiles> - <modules> - <module>rave-core-tests</module> - <module>rave-newuser-tests</module> - <module>rave-admin-tests</module> - <module>rave-default-account-tests</module> - </modules> </project> http://git-wip-us.apache.org/repos/asf/rave/blob/b7cd8dea/rave-integration-tests/rave-webservice-tests/pom.xml ---------------------------------------------------------------------- diff --git a/rave-integration-tests/rave-webservice-tests/pom.xml b/rave-integration-tests/rave-webservice-tests/pom.xml new file mode 100644 index 0000000..995b220 --- /dev/null +++ b/rave-integration-tests/rave-webservice-tests/pom.xml @@ -0,0 +1,128 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>rave-integration-tests</artifactId> + <groupId>org.apache.rave.integration-tests</groupId> + <version>0.24-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.rave.integration-tests</groupId> + <artifactId>rave-webservice-tests</artifactId> + <version>0.24-SNAPSHOT</version> + <name>Apache Rave :: rave-webservice-tests</name> + <description>Integration tests verifying webservice functionality</description> + + + <properties> + <embeddables>**/*Stories.java</embeddables> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.rave</groupId> + <artifactId>rave-core-api</artifactId> + </dependency> + <dependency> + <groupId>org.jbehave</groupId> + <artifactId>jbehave-core</artifactId> + <version>${jbehave.core.version}</version> + </dependency> + <dependency> + <groupId>org.jbehave.site</groupId> + <artifactId>jbehave-site-resources</artifactId> + <version>${jbehave.site.version}</version> + <type>zip</type> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-frontend-jaxrs</artifactId> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-core</artifactId> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.jaxrs</groupId> + <artifactId>jackson-jaxrs-json-provider</artifactId> + </dependency> + </dependencies> + + <build> + <resources> + <resource> + <directory>src/main/java</directory> + <filtering>true</filtering> + <excludes> + <exclude>**/*.java</exclude> + </excludes> + </resource> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skipTests>true</skipTests> + </configuration> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>notest</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + </profile> + <profile> + <id>integration-tests</id> + <build> + <defaultGoal>integration-test</defaultGoal> + <plugins> + <plugin> + <groupId>org.jbehave</groupId> + <artifactId>jbehave-maven-plugin</artifactId> + <version>${jbehave.core.version}</version> + <executions> + <execution> + <id>unpack-view-resources</id> + <phase>process-resources</phase> + <goals> + <goal>unpack-view-resources</goal> + </goals> + </execution> + <execution> + <id>embeddable-stories</id> + <phase>integration-test</phase> + <configuration> + <includes> + <include>${embeddables}</include> + </includes> + <excludes/> + <ignoreFailureInStories>false</ignoreFailureInStories> + <ignoreFailureInView>false</ignoreFailureInView> + <threads>1</threads> + <storyTimeoutInSecs>600</storyTimeoutInSecs> + <metaFilters> + <metaFilter></metaFilter> + </metaFilters> + </configuration> + <goals> + <goal>run-stories-as-embeddables</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> http://git-wip-us.apache.org/repos/asf/rave/blob/b7cd8dea/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/StateManager.java ---------------------------------------------------------------------- diff --git a/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/StateManager.java b/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/StateManager.java new file mode 100644 index 0000000..ff7c761 --- /dev/null +++ b/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/StateManager.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rave.integrationtests.webservice; + +import java.util.HashMap; + +public class StateManager { + private static HashMap<String, HashMap<String, Object>> stateMap = new HashMap<String, HashMap<String, Object>>(); + + public StateManager() { + throw new AssertionError("Instantiating utility class..."); + } + + public static HashMap<String, Object> getStateStore(String instanceID) { + if (!stateMap.containsKey(instanceID)) { + stateMap.put(instanceID, new HashMap<String, Object>()); + } + + return stateMap.get(instanceID); + } +} http://git-wip-us.apache.org/repos/asf/rave/blob/b7cd8dea/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/Stories.java ---------------------------------------------------------------------- diff --git a/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/Stories.java b/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/Stories.java new file mode 100644 index 0000000..1757cf8 --- /dev/null +++ b/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/Stories.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rave.integrationtests.webservice; + +import org.apache.rave.integrationtests.webservice.steps.CommonSteps; +import org.apache.rave.integrationtests.webservice.steps.PeopleSteps; +import org.jbehave.core.Embeddable; +import org.jbehave.core.configuration.Configuration; +import org.jbehave.core.configuration.MostUsefulConfiguration; +import org.jbehave.core.i18n.LocalizedKeywords; +import org.jbehave.core.io.CodeLocations; +import org.jbehave.core.io.LoadFromClasspath; +import org.jbehave.core.io.StoryFinder; +import org.jbehave.core.junit.JUnitStories; +import org.jbehave.core.model.ExamplesTableFactory; +import org.jbehave.core.parsers.RegexStoryParser; +import org.jbehave.core.reporters.StoryReporterBuilder; +import org.jbehave.core.steps.InjectableStepsFactory; +import org.jbehave.core.steps.InstanceStepsFactory; +import org.jbehave.core.steps.ParameterConverters; +import org.jbehave.core.steps.ParameterConverters.DateConverter; + +import java.text.SimpleDateFormat; +import java.util.*; + +import static org.jbehave.core.io.CodeLocations.codeLocationFromClass; +import static org.jbehave.core.reporters.Format.*; + +/** + * <p> + * {@link Embeddable} class to run multiple textual steps via JUnit. + * </p> + * <p> + * Stories are specified in classpath and correspondingly the {@link LoadFromClasspath} story loader is configured. + * </p> + */ +public class Stories extends JUnitStories { + + public Stories() { + configuredEmbedder().embedderControls().doGenerateViewAfterStories(true).doIgnoreFailureInStories(true) + .doIgnoreFailureInView(false).useThreads(1).useStoryTimeoutInSecs(600); + } + + @Override + public Configuration configuration() { + Class<? extends Embeddable> embeddableClass = this.getClass(); + // Start from default ParameterConverters instance + ParameterConverters parameterConverters = new ParameterConverters(); + // factory to allow parameter conversion and loading from external resources (used by StoryParser too) + ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(new LocalizedKeywords(), new LoadFromClasspath(embeddableClass), parameterConverters); + // add custom converters + parameterConverters.addConverters( + new DateConverter(new SimpleDateFormat("yyyy-MM-dd")), + new ParameterConverters.EnumConverter() + ); + return new MostUsefulConfiguration() + .useStoryLoader(new LoadFromClasspath(embeddableClass)) + .useStoryParser(new RegexStoryParser(examplesTableFactory)) + .useStoryReporterBuilder(new StoryReporterBuilder() + .withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass)) + .withDefaultFormats() + .withFormats(CONSOLE, TXT, HTML, XML)) + .useParameterConverters(parameterConverters); + } + + @Override + public InjectableStepsFactory stepsFactory() { + return new InstanceStepsFactory(configuration(), + new CommonSteps(), + new PeopleSteps() + ); + } + + @Override + protected List<String> storyPaths() { + String story = System.getProperty("story"); + if (story != null && !story.isEmpty()) { + return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/" + story + ".story", "**/excluded*.story"); + } else { + return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/*.story", "**/excluded*.story"); + } + + } + +} http://git-wip-us.apache.org/repos/asf/rave/blob/b7cd8dea/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/steps/CommonSteps.java ---------------------------------------------------------------------- diff --git a/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/steps/CommonSteps.java b/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/steps/CommonSteps.java new file mode 100644 index 0000000..9b2a45d --- /dev/null +++ b/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/steps/CommonSteps.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rave.integrationtests.webservice.steps; + +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.rave.integrationtests.webservice.StateManager; +import org.jbehave.core.annotations.Given; +import org.jbehave.core.annotations.When; + +import javax.ws.rs.core.MediaType; +import java.util.Collections; +import java.util.HashMap; + +public class CommonSteps { + public static final String KEY_WEB_CLIENT = "webclient"; + private final String baseURL = "http://localhost:8080/portal/api/rest"; + + @Given("the user \"$username\" with the password of \"$password\" is logged into the system expecting \"$datatype\"") + public void userIsLoggedIn(String username, String password, String datatype) { + WebClient client; + + if (datatype.equals("JSON")) { + JacksonJsonProvider json = new JacksonJsonProvider(); + + client = WebClient.create(baseURL, Collections.singletonList(json), true); + client.type(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON_TYPE); + } else { + client = WebClient.create(baseURL, true); + client.type(MediaType.APPLICATION_XML_TYPE).accept(MediaType.APPLICATION_XML_TYPE); + } + String authorizationHeader = "Basic " + + org.apache.cxf.common.util.Base64Utility.encode((username + ":" + password).getBytes()); + client.header("Authorization", authorizationHeader); + + getState().put(KEY_WEB_CLIENT, client); + } + + @When("the user waits \"$count\" seconds") + public void userWaits(int seconds) throws Exception { + Thread.sleep(seconds * 1000); + } + + private HashMap<String, Object> getState() { + return StateManager.getStateStore(new String(Long.toString(Thread.currentThread().getId()))); + } +} http://git-wip-us.apache.org/repos/asf/rave/blob/b7cd8dea/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/steps/PeopleSteps.java ---------------------------------------------------------------------- diff --git a/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/steps/PeopleSteps.java b/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/steps/PeopleSteps.java new file mode 100644 index 0000000..f6829ab --- /dev/null +++ b/rave-integration-tests/rave-webservice-tests/src/main/java/org/apache/rave/integrationtests/webservice/steps/PeopleSteps.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rave.integrationtests.webservice.steps; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.rave.integrationtests.webservice.StateManager; +import org.apache.rave.rest.model.JsonResponseWrapper; +import org.apache.rave.rest.model.Person; +import org.jbehave.core.annotations.Given; +import org.jbehave.core.annotations.Then; +import org.jbehave.core.annotations.When; + +import javax.ws.rs.core.Response; + +import static junit.framework.TestCase.fail; +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.*; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; + +public class PeopleSteps { + + private static final String URL_PEOPLE = "/people/"; + + private static final String KEY_ACTIVE_PERSON = "active_person"; + + private static ObjectMapper mapper = new ObjectMapper(); + + @Given("the system contains \"$count\" people") + @Then("there should be \"$count\" people in the system") + public void countPeople(int count) throws Exception { + assertThat("Wrong number of people", getAllPeople().size(), equalTo(count)); + } + + @When("the user retrieves the full person record for the display name of \"$displayName\"") + public void getUserByDisplayName(String displayName) throws Exception { + for (Person person : getAllPeople()) { + if (person.getDisplayName().equals(displayName)) { + getState().put(KEY_ACTIVE_PERSON, getPerson(person.getId())); + return; + } + } + + assert false; + } + + @Then("the \"$field\" field on the active person object is \"$value\"") + public void validateFieldOnActivePersonWithValue(String field, String value) { + validateFieldOnActivePerson(field, value); + } + + @Then("the \"$field\" field on the active person object is null") + public void validateFieldOnActivePersonIsNull(String field) { + validateFieldOnActivePerson(field, null); + } + + private void validateFieldOnActivePerson(String field, String value) { + Person person = (Person)getState().get(KEY_ACTIVE_PERSON); + assertThat("Active Person is Null", person, notNullValue()); + + for (Method method : person.getClass().getMethods()) { + if (method.getName().toLowerCase().equals("get" + field.toLowerCase())) { + try { + String val = (String)method.invoke(person); + assertThat("Value doesn't match", val, equalTo(value)); + return; + } catch (Exception ex) { + fail("Exception thrown"); + } + } + } + + fail("Method not found"); + } + + private List<Person> getAllPeople() throws Exception { + WebClient webClient = getClient(); + List<Person> people = new ArrayList<Person>(); + for (Object obj : (List<Object>)webClient.path(URL_PEOPLE).get(JsonResponseWrapper.class).getData()) { + people.add(mapper.readValue(mapper.writeValueAsString(obj), Person.class)); + } + return people; + } + + private Person getPerson(String id) throws Exception { + WebClient webClient = getClient(); + Object person = webClient.path(URL_PEOPLE + id).get(JsonResponseWrapper.class).getData(); + return mapper.readValue(mapper.writeValueAsString(person), Person.class); + } + + private WebClient getClient() { + WebClient client = (WebClient) getState().get(CommonSteps.KEY_WEB_CLIENT); + client.back(true); + client.resetQuery(); + return client; + } + + private HashMap<String, Object> getState() { + return StateManager.getStateStore(new String(Long.toString(Thread.currentThread().getId()))); + } +} http://git-wip-us.apache.org/repos/asf/rave/blob/b7cd8dea/rave-integration-tests/rave-webservice-tests/src/main/resources/org/apache/rave/integrationtests/webservice/people.story ---------------------------------------------------------------------- diff --git a/rave-integration-tests/rave-webservice-tests/src/main/resources/org/apache/rave/integrationtests/webservice/people.story b/rave-integration-tests/rave-webservice-tests/src/main/resources/org/apache/rave/integrationtests/webservice/people.story new file mode 100644 index 0000000..b9818cb --- /dev/null +++ b/rave-integration-tests/rave-webservice-tests/src/main/resources/org/apache/rave/integrationtests/webservice/people.story @@ -0,0 +1,40 @@ +!-- +!-- Licensed to the Apache Software Foundation (ASF) under one +!-- or more contributor license agreements. See the NOTICE file +!-- distributed with this work for additional information +!-- regarding copyright ownership. The ASF licenses this file +!-- to you under the Apache License, Version 2.0 (the +!-- "License"); you may not use this file except in compliance +!-- with the License. You may obtain a copy of the License at +!-- +!-- http://www.apache.org/licenses/LICENSE-2.0 +!-- +!-- Unless required by applicable law or agreed to in writing, +!-- software distributed under the License is distributed on an +!-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +!-- KIND, either express or implied. See the License for the +!-- specific language governing permissions and limitations +!-- under the License. +!-- + +Scenario: The system is set to a known state + +Given the user "canonical" with the password of "canonical" is logged into the system expecting "JSON" +Then there should be "13" people in the system + + +Scenario: The user finds their record in the list and retrieves their full record + +Given the system contains "13" people +When the user retrieves the full person record for the display name of "Canonical User" +Then the "username" field on the active person object is "canonical" +And the "emailAddress" field on the active person object is "[email protected]" +And the "displayName" field on the active person object is "Canonical User" +And the "aboutMe" field on the active person object is null +And the "preferredName" field on the active person object is null +And the "status" field on the active person object is "Single" +And the "additionalName" field on the active person object is "canonical" +And the "familyName" field on the active person object is "User" +And the "givenName" field on the active person object is "Canonical" +And the "honorificPrefix" field on the active person object is null +And the "honorificSuffix" field on the active person object is null \ No newline at end of file http://git-wip-us.apache.org/repos/asf/rave/blob/b7cd8dea/rave-portal-resources/src/main/webapp/WEB-INF/applicationContext-security.xml ---------------------------------------------------------------------- diff --git a/rave-portal-resources/src/main/webapp/WEB-INF/applicationContext-security.xml b/rave-portal-resources/src/main/webapp/WEB-INF/applicationContext-security.xml index 6f94437..bd7c23f 100644 --- a/rave-portal-resources/src/main/webapp/WEB-INF/applicationContext-security.xml +++ b/rave-portal-resources/src/main/webapp/WEB-INF/applicationContext-security.xml @@ -61,6 +61,7 @@ <security:openid-attribute name="fullname" type="http://schema.openid.net/namePerson" required="true"/> </security:attribute-exchange> </security:openid-login> + <security:http-basic/> <security:form-login login-page="/login" default-target-url="/" authentication-failure-url="/login?authfail=form" /> <security:logout/> <security:remember-me user-service-ref="userService" />
