-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OPENENGSB-3876] Integration test for userprojectsfile connector
- Loading branch information
Showing
5 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
158 changes: 158 additions & 0 deletions
158
itests/src/test/java/org/openengsb/itests/exam/UserProjectsFileConnectorIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/** | ||
* Licensed to the Austrian Association for Software Tool Integration (AASTI) | ||
* under one or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information regarding copyright | ||
* ownership. The AASTI 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.openengsb.itests.exam; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.hamcrest.CoreMatchers; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.openengsb.core.ekb.api.QueryInterface; | ||
import org.openengsb.domain.userprojects.UserProjectsDomain; | ||
import org.openengsb.domain.userprojects.model.Assignment; | ||
import org.openengsb.domain.userprojects.model.Project; | ||
import org.openengsb.domain.userprojects.model.Role; | ||
import org.openengsb.domain.userprojects.model.User; | ||
import org.openengsb.itests.util.AbstractPreConfiguredExamTestHelper; | ||
import org.ops4j.pax.exam.junit.PaxExam; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
@RunWith(PaxExam.class) | ||
public class UserProjectsFileConnectorIT extends AbstractPreConfiguredExamTestHelper { | ||
|
||
private static final String BASE_DIR = "data/userprojectsfile"; | ||
private static final File ASSIGNMENTS_FILE = new File(BASE_DIR, "assignments"); | ||
private static final File PROJECTS_FILE = new File(BASE_DIR, "projects"); | ||
private static final File ROLES_FILE = new File(BASE_DIR, "roles"); | ||
private static final File USERS_FILE = new File(BASE_DIR, "users"); | ||
|
||
private List<Assignment> assignments = new ArrayList<>(); | ||
private List<Project> projects = new ArrayList<>(); | ||
private List<Role> roles = new ArrayList<>(); | ||
private List<User> users = new ArrayList<>(); | ||
|
||
@Inject | ||
private QueryInterface queryInterface; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
authenticateAsAdmin(); | ||
setupAssignments(); | ||
setupProjects(); | ||
setupRoles(); | ||
setupUsers(); | ||
} | ||
|
||
private void setupAssignments() { | ||
Assignment assignment = new Assignment("user1", "project1"); | ||
assignment.setRoles(Lists.newArrayList("role1", "role2")); | ||
assignments.add(assignment); | ||
|
||
assignments.add(new Assignment("user2", "project2")); | ||
assignments.add(new Assignment("user1", "project2")); | ||
} | ||
|
||
private void setupProjects() { | ||
projects.add(new Project("project1")); | ||
projects.add(new Project("project2")); | ||
} | ||
|
||
private void setupRoles() { | ||
roles.add(new Role("role1")); | ||
roles.add(new Role("role2")); | ||
Role role = new Role("role3"); | ||
role.setRoles(Arrays.asList("role1", "role2")); | ||
roles.add(role); | ||
roles.add(new Role("role4")); | ||
} | ||
|
||
private void setupUsers() { | ||
users.add(new User("user1")); | ||
users.add(new User("user2")); | ||
} | ||
|
||
@Test | ||
public void testSyncFromFilesToOpenEngSB_shouldThrowTheRespectiveEvents() throws InterruptedException, | ||
IOException { | ||
assertTrue(queryInterface.queryForActiveModels(Assignment.class).isEmpty()); | ||
assertTrue(queryInterface.queryForActiveModels(Project.class).isEmpty()); | ||
assertTrue(queryInterface.queryForActiveModels(Role.class).isEmpty()); | ||
assertTrue(queryInterface.queryForActiveModels(User.class).isEmpty()); | ||
|
||
getOsgiService(UserProjectsDomain.class, 5000); | ||
copyFiles(); | ||
Thread.sleep(10000); | ||
|
||
assertAssignmentsExist(queryInterface.queryForActiveModels(Assignment.class)); | ||
assertProjectsExist(queryInterface.queryForActiveModels(Project.class)); | ||
assertRolesExist(queryInterface.queryForActiveModels(Role.class)); | ||
assertUsersExist(queryInterface.queryForActiveModels(User.class)); | ||
|
||
for (User user : users) { | ||
System.out.println(user.getUsername()); | ||
} | ||
|
||
} | ||
|
||
private void assertAssignmentsExist(List<Assignment> actualAssignments) { | ||
Assert.assertThat(actualAssignments, | ||
CoreMatchers.hasItems(assignments.toArray(new Assignment[assignments.size()]))); | ||
} | ||
|
||
private void assertProjectsExist(List<Project> actualProjects) { | ||
Assert.assertThat(actualProjects, CoreMatchers.hasItems(projects.toArray(new Project[projects.size()]))); | ||
} | ||
|
||
private void assertRolesExist(List<Role> actualRoles) { | ||
Assert.assertThat(actualRoles, CoreMatchers.hasItems(roles.toArray(new Role[roles.size()]))); | ||
} | ||
|
||
private void assertUsersExist(List<User> actualUsers) { | ||
Assert.assertThat(actualUsers, CoreMatchers.hasItems(users.toArray(new User[users.size()]))); | ||
} | ||
|
||
private void copyFiles() throws IOException { | ||
copyFile(ASSIGNMENTS_FILE); | ||
copyFile(PROJECTS_FILE); | ||
copyFile(ROLES_FILE); | ||
copyFile(USERS_FILE); | ||
} | ||
|
||
private void copyFile(File file) throws IOException { | ||
Files.createDirectories(file.getParentFile().toPath()); | ||
Files.copy(getFileAsStream(file), Paths.get(file.getPath())); | ||
} | ||
|
||
private InputStream getFileAsStream(File file) { | ||
return getClass().getClassLoader().getResourceAsStream(file.getPath().replaceAll(File.separator, "/")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
user1:-:project1:-:role1,-,role2 | ||
user2:-:project2 | ||
|
||
user1 | ||
user2:-: | ||
|
||
user1:-:project2:-: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
project1 | ||
|
||
project2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
role1 | ||
role2 | ||
|
||
role3:-:role1,-,role2 | ||
|
||
role4:-: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
user1 | ||
|
||
user2 |