You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2015/01/12 17:31:58 UTC
[19/52] [abbrv] [partial] syncope git commit: [SYNCOPE-620] Unit
tests all in
http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/AttributableSearchTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/AttributableSearchTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/AttributableSearchTest.java
deleted file mode 100644
index 2f54395..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/AttributableSearchTest.java
+++ /dev/null
@@ -1,484 +0,0 @@
-/*
- * 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.syncope.persistence.jpa.entity;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import org.apache.syncope.common.lib.types.SubjectType;
-import org.apache.syncope.persistence.api.RoleEntitlementUtil;
-import org.apache.syncope.persistence.api.dao.EntitlementDAO;
-import org.apache.syncope.persistence.api.dao.RoleDAO;
-import org.apache.syncope.persistence.api.dao.SubjectSearchDAO;
-import org.apache.syncope.persistence.api.dao.UserDAO;
-import org.apache.syncope.persistence.api.dao.search.AttributeCond;
-import org.apache.syncope.persistence.api.dao.search.MembershipCond;
-import org.apache.syncope.persistence.api.dao.search.OrderByClause;
-import org.apache.syncope.persistence.api.dao.search.ResourceCond;
-import org.apache.syncope.persistence.api.dao.search.SearchCond;
-import org.apache.syncope.persistence.api.dao.search.SubjectCond;
-import org.apache.syncope.persistence.api.entity.role.Role;
-import org.apache.syncope.persistence.api.entity.user.User;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.transaction.annotation.Transactional;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = { "classpath:persistenceTestEnv.xml" })
-@Transactional
-public class AttributableSearchTest {
-
- @Autowired
- private UserDAO userDAO;
-
- @Autowired
- private RoleDAO roleDAO;
-
- @Autowired
- private SubjectSearchDAO searchDAO;
-
- @Autowired
- private EntitlementDAO entitlementDAO;
-
- @Test
- public void userMatch() {
- User user = userDAO.find(1L);
- assertNotNull(user);
-
- MembershipCond membershipCond = new MembershipCond();
- membershipCond.setRoleId(5L);
-
- assertFalse(searchDAO.matches(user, SearchCond.getLeafCond(membershipCond), SubjectType.USER));
-
- membershipCond.setRoleId(1L);
-
- assertTrue(searchDAO.matches(user, SearchCond.getLeafCond(membershipCond), SubjectType.USER));
- }
-
- @Test
- public void roleMatch() {
- Role role = roleDAO.find(1L);
- assertNotNull(role);
-
- AttributeCond attrCond = new AttributeCond();
- attrCond.setSchema("show");
- attrCond.setType(AttributeCond.Type.ISNOTNULL);
-
- assertTrue(searchDAO.matches(role, SearchCond.getLeafCond(attrCond), SubjectType.ROLE));
- }
-
- @Test
- public void searchWithLikeCondition() {
- AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.LIKE);
- fullnameLeafCond.setSchema("fullname");
- fullnameLeafCond.setExpression("%o%");
-
- MembershipCond membershipCond = new MembershipCond();
- membershipCond.setRoleId(1L);
-
- AttributeCond loginDateCond = new AttributeCond(AttributeCond.Type.EQ);
- loginDateCond.setSchema("loginDate");
- loginDateCond.setExpression("2009-05-26");
-
- SearchCond subCond = SearchCond.getAndCond(SearchCond.getLeafCond(fullnameLeafCond), SearchCond.getLeafCond(
- membershipCond));
-
- assertTrue(subCond.isValid());
-
- SearchCond cond = SearchCond.getAndCond(subCond, SearchCond.getLeafCond(loginDateCond));
-
- assertTrue(cond.isValid());
-
- List<User> users =
- searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), cond, SubjectType.USER);
- assertNotNull(users);
- assertEquals(1, users.size());
- }
-
- @Test
- public void searchWithNotCondition() {
- AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.EQ);
- fullnameLeafCond.setSchema("fullname");
- fullnameLeafCond.setExpression("Giuseppe Verdi");
-
- SearchCond cond = SearchCond.getNotLeafCond(fullnameLeafCond);
- assertTrue(cond.isValid());
-
- List<User> users =
- searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), cond, SubjectType.USER);
- assertNotNull(users);
- assertEquals(4, users.size());
-
- Set<Long> ids = new HashSet<Long>(users.size());
- for (User user : users) {
- ids.add(user.getKey());
- }
- assertTrue(ids.contains(1L));
- assertTrue(ids.contains(3L));
- }
-
- @Test
- public void searchByBoolean() {
- AttributeCond coolLeafCond = new AttributeCond(AttributeCond.Type.EQ);
- coolLeafCond.setSchema("cool");
- coolLeafCond.setExpression("true");
-
- SearchCond cond = SearchCond.getLeafCond(coolLeafCond);
- assertTrue(cond.isValid());
-
- List<User> users =
- searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), cond, SubjectType.USER);
- assertNotNull(users);
- assertEquals(1, users.size());
-
- assertEquals(Long.valueOf(4L), users.get(0).getKey());
- }
-
- @Test
- public void searchByPageAndSize() {
- AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.LIKE);
- fullnameLeafCond.setSchema("fullname");
- fullnameLeafCond.setExpression("%o%");
-
- MembershipCond membershipCond = new MembershipCond();
- membershipCond.setRoleId(1L);
-
- AttributeCond loginDateCond = new AttributeCond(AttributeCond.Type.EQ);
- loginDateCond.setSchema("loginDate");
- loginDateCond.setExpression("2009-05-26");
-
- SearchCond subCond = SearchCond.getAndCond(SearchCond.getLeafCond(fullnameLeafCond), SearchCond.getLeafCond(
- membershipCond));
-
- assertTrue(subCond.isValid());
-
- SearchCond cond = SearchCond.getAndCond(subCond, SearchCond.getLeafCond(loginDateCond));
-
- assertTrue(cond.isValid());
-
- List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
- cond, 1, 2, Collections.<OrderByClause>emptyList(),
- SubjectType.USER);
- assertNotNull(users);
- assertEquals(1, users.size());
-
- users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
- cond, 2, 2, Collections.<OrderByClause>emptyList(),
- SubjectType.USER);
- assertNotNull(users);
- assertTrue(users.isEmpty());
- }
-
- @Test
- public void searchByMembership() {
- MembershipCond membershipCond = new MembershipCond();
- membershipCond.setRoleId(1L);
-
- List<User> users = searchDAO.search(
- RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), SearchCond.getLeafCond(membershipCond),
- SubjectType.USER);
- assertNotNull(users);
- assertEquals(2, users.size());
-
- membershipCond = new MembershipCond();
- membershipCond.setRoleId(5L);
-
- users = searchDAO.search(
- RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), SearchCond.getNotLeafCond(membershipCond),
- SubjectType.USER);
- assertNotNull(users);
- assertEquals(5, users.size());
- }
-
- @Test
- public void searchByIsNull() {
- AttributeCond coolLeafCond = new AttributeCond(AttributeCond.Type.ISNULL);
- coolLeafCond.setSchema("cool");
-
- List<User> users = searchDAO.search(
- RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), SearchCond.getLeafCond(coolLeafCond),
- SubjectType.USER);
- assertNotNull(users);
- assertEquals(4, users.size());
-
- coolLeafCond = new AttributeCond(AttributeCond.Type.ISNOTNULL);
- coolLeafCond.setSchema("cool");
-
- users = searchDAO.search(
- RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), SearchCond.getLeafCond(coolLeafCond),
- SubjectType.USER);
- assertNotNull(users);
- assertEquals(1, users.size());
- }
-
- @Test
- public void searchByResource() {
- ResourceCond ws2 = new ResourceCond();
- ws2.setResourceName("ws-target-resource-2");
-
- ResourceCond ws1 = new ResourceCond();
- ws1.setResourceName("ws-target-resource-list-mappings-2");
-
- SearchCond searchCondition = SearchCond.getAndCond(SearchCond.getNotLeafCond(ws2), SearchCond.getLeafCond(ws1));
-
- assertTrue(searchCondition.isValid());
-
- List<User> users = searchDAO.search(
- RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCondition,
- SubjectType.USER);
-
- assertNotNull(users);
- assertEquals(1, users.size());
- }
-
- @Test
- public void searchByUsernameAndId() {
- SubjectCond usernameLeafCond = new SubjectCond(SubjectCond.Type.EQ);
- usernameLeafCond.setSchema("username");
- usernameLeafCond.setExpression("rossini");
-
- SubjectCond idRightCond = new SubjectCond(SubjectCond.Type.LT);
- idRightCond.setSchema("id");
- idRightCond.setExpression("2");
-
- SearchCond searchCondition = SearchCond.getOrCond(SearchCond.getLeafCond(usernameLeafCond),
- SearchCond.getLeafCond(idRightCond));
-
- List<User> matchingUsers = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
- searchCondition, SubjectType.USER);
-
- assertNotNull(matchingUsers);
- assertEquals(1, matchingUsers.size());
- assertEquals("rossini", matchingUsers.iterator().next().getUsername());
- assertEquals(1L, matchingUsers.iterator().next().getKey().longValue());
- }
-
- @Test
- public void searchByRolenameAndId() {
- SubjectCond rolenameLeafCond = new SubjectCond(SubjectCond.Type.EQ);
- rolenameLeafCond.setSchema("name");
- rolenameLeafCond.setExpression("root");
-
- SubjectCond idRightCond = new SubjectCond(SubjectCond.Type.LT);
- idRightCond.setSchema("id");
- idRightCond.setExpression("2");
-
- SearchCond searchCondition = SearchCond.getAndCond(SearchCond.getLeafCond(rolenameLeafCond),
- SearchCond.getLeafCond(idRightCond));
-
- assertTrue(searchCondition.isValid());
-
- List<Role> matchingRoles = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
- searchCondition, SubjectType.ROLE);
-
- assertNotNull(matchingRoles);
- assertEquals(1, matchingRoles.size());
- assertEquals("root", matchingRoles.iterator().next().getName());
- assertEquals(1L, matchingRoles.iterator().next().getKey().longValue());
- }
-
- @Test
- public void searchByUsernameAndFullname() {
- SubjectCond usernameLeafCond = new SubjectCond(SubjectCond.Type.EQ);
- usernameLeafCond.setSchema("username");
- usernameLeafCond.setExpression("rossini");
-
- AttributeCond idRightCond = new AttributeCond(AttributeCond.Type.LIKE);
- idRightCond.setSchema("fullname");
- idRightCond.setExpression("Giuseppe V%");
-
- SearchCond searchCondition = SearchCond.getOrCond(SearchCond.getLeafCond(usernameLeafCond),
- SearchCond.getLeafCond(idRightCond));
-
- List<User> matchingUsers =
- searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCondition,
- SubjectType.USER);
-
- assertNotNull(matchingUsers);
- assertEquals(2, matchingUsers.size());
- }
-
- @Test
- public void searchById() {
- SubjectCond idLeafCond = new SubjectCond(SubjectCond.Type.LT);
- idLeafCond.setSchema("id");
- idLeafCond.setExpression("2");
-
- SearchCond searchCondition = SearchCond.getLeafCond(idLeafCond);
- assertTrue(searchCondition.isValid());
-
- List<User> users =
- searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCondition,
- SubjectType.USER);
-
- assertNotNull(users);
- assertEquals(1, users.size());
- assertEquals(1L, users.iterator().next().getKey().longValue());
-
- idLeafCond = new SubjectCond(SubjectCond.Type.LT);
- idLeafCond.setSchema("id");
- idLeafCond.setExpression("4");
-
- searchCondition = SearchCond.getNotLeafCond(idLeafCond);
- assertTrue(searchCondition.isValid());
-
- users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCondition,
- SubjectType.USER);
-
- assertNotNull(users);
- assertEquals(2, users.size());
- boolean found = false;
- for (User user : users) {
- if (user.getKey() == 4) {
- found = true;
- }
- }
- assertTrue(found);
- }
-
- @Test
- public void userOrderBy() {
- SubjectCond usernameLeafCond = new SubjectCond(SubjectCond.Type.EQ);
- usernameLeafCond.setSchema("username");
- usernameLeafCond.setExpression("rossini");
- AttributeCond idRightCond = new AttributeCond(AttributeCond.Type.LIKE);
- idRightCond.setSchema("fullname");
- idRightCond.setExpression("Giuseppe V%");
- SearchCond searchCondition = SearchCond.getOrCond(
- SearchCond.getLeafCond(usernameLeafCond), SearchCond.getLeafCond(idRightCond));
-
- List<OrderByClause> orderByClauses = new ArrayList<OrderByClause>();
- OrderByClause orderByClause = new OrderByClause();
- orderByClause.setField("username");
- orderByClause.setDirection(OrderByClause.Direction.DESC);
- orderByClauses.add(orderByClause);
- orderByClause = new OrderByClause();
- orderByClause.setField("fullname");
- orderByClause.setDirection(OrderByClause.Direction.ASC);
- orderByClauses.add(orderByClause);
-
- List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
- searchCondition, Collections.singletonList(orderByClause),
- SubjectType.USER);
- assertEquals(searchDAO.count(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
- searchCondition, SubjectType.USER),
- users.size());
- }
-
- @Test
- public void roleOrderBy() {
- SubjectCond idLeafCond = new SubjectCond(SubjectCond.Type.LIKE);
- idLeafCond.setSchema("name");
- idLeafCond.setExpression("%r");
- SearchCond searchCondition = SearchCond.getLeafCond(idLeafCond);
- assertTrue(searchCondition.isValid());
-
- OrderByClause orderByClause = new OrderByClause();
- orderByClause.setField("name");
-
- List<Role> roles = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
- searchCondition, Collections.singletonList(orderByClause), SubjectType.ROLE);
- assertEquals(searchDAO.count(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
- searchCondition, SubjectType.ROLE),
- roles.size());
- }
-
- @Test
- public void issue202() {
- ResourceCond ws2 = new ResourceCond();
- ws2.setResourceName("ws-target-resource-2");
-
- ResourceCond ws1 = new ResourceCond();
- ws1.setResourceName("ws-target-resource-list-mappings-1");
-
- SearchCond searchCondition =
- SearchCond.getAndCond(SearchCond.getNotLeafCond(ws2), SearchCond.getNotLeafCond(ws1));
- assertTrue(searchCondition.isValid());
-
- List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
- searchCondition, SubjectType.USER);
- assertNotNull(users);
- assertEquals(2, users.size());
- boolean found = false;
- for (User user : users) {
- if (user.getKey() == 4) {
- found = true;
- }
- }
- assertTrue(found);
- }
-
- @Test
- public void issue242() {
- SubjectCond cond = new SubjectCond(AttributeCond.Type.LIKE);
- cond.setSchema("id");
- cond.setExpression("test%");
-
- SearchCond searchCondition = SearchCond.getLeafCond(cond);
- assertTrue(searchCondition.isValid());
-
- List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
- searchCondition, SubjectType.USER);
- assertNotNull(users);
- assertTrue(users.isEmpty());
- }
-
- @Test
- public void issueSYNCOPE46() {
- SubjectCond cond = new SubjectCond(AttributeCond.Type.LIKE);
- cond.setSchema("username");
- cond.setExpression("%ossin%");
-
- SearchCond searchCondition = SearchCond.getLeafCond(cond);
- assertTrue(searchCondition.isValid());
-
- List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
- searchCondition, SubjectType.USER);
- assertNotNull(users);
- assertEquals(1, users.size());
- }
-
- @Test
- public void issueSYNCOPE433() {
- AttributeCond isNullCond = new AttributeCond(AttributeCond.Type.ISNULL);
- isNullCond.setSchema("loginDate");
-
- SubjectCond likeCond = new SubjectCond(AttributeCond.Type.LIKE);
- likeCond.setSchema("username");
- likeCond.setExpression("%ossin%");
-
- SearchCond searchCond = SearchCond.getOrCond(
- SearchCond.getLeafCond(isNullCond), SearchCond.getLeafCond(likeCond));
-
- Integer count = searchDAO.count(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCond,
- SubjectType.USER);
- assertNotNull(count);
- assertTrue(count > 0);
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ConfTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ConfTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ConfTest.java
deleted file mode 100644
index 143a4fe..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ConfTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.syncope.persistence.jpa.entity;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.apache.syncope.common.lib.types.AttrSchemaType;
-import org.apache.syncope.common.lib.types.AttributableType;
-import org.apache.syncope.common.lib.types.EntityViolationType;
-import org.apache.syncope.persistence.api.attrvalue.validation.InvalidEntityException;
-import org.apache.syncope.persistence.api.dao.ConfDAO;
-import org.apache.syncope.persistence.api.dao.PlainSchemaDAO;
-import org.apache.syncope.persistence.api.entity.conf.CPlainAttr;
-import org.apache.syncope.persistence.api.entity.conf.CPlainSchema;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class ConfTest extends AbstractTest {
-
- @Autowired
- private ConfDAO confDAO;
-
- @Autowired
- private PlainSchemaDAO plainSchemaDAO;
-
- @Test
- public void read() {
- CPlainAttr conf = confDAO.find("selfRegistration.allowed");
- assertNotNull(conf);
- assertTrue(conf.getValues().get(0).getBooleanValue());
-
- conf = confDAO.find("authentication.statuses");
- assertNotNull(conf);
- assertEquals(2, conf.getValues().size());
-
- conf = confDAO.find("non.existing");
- assertNull(conf);
- }
-
- @Test
- public void setAndDelete() {
- // 1. create CSChema
- CPlainSchema useless = entityFactory.newEntity(CPlainSchema.class);
- useless.setKey("useless");
- useless.setType(AttrSchemaType.Date);
- useless.setConversionPattern("yyyy-MM-dd");
- useless = plainSchemaDAO.save(useless);
-
- // 2. create conf
- CPlainAttr newConf = entityFactory.newEntity(CPlainAttr.class);
- newConf.setSchema(useless);
- newConf.addValue("2014-06-20", attrUtilFactory.getInstance(AttributableType.CONFIGURATION));
- confDAO.save(newConf);
-
- CPlainAttr actual = confDAO.find("useless");
- assertEquals(actual.getValuesAsStrings(), newConf.getValuesAsStrings());
-
- // 3. update conf
- newConf.getValues().clear();
- newConf.addValue("2014-06-20", attrUtilFactory.getInstance(AttributableType.CONFIGURATION));
- confDAO.save(newConf);
-
- actual = confDAO.find("useless");
- assertEquals(actual.getValuesAsStrings(), newConf.getValuesAsStrings());
-
- // 4. delete conf
- confDAO.delete("useless");
- assertNull(confDAO.find("useless"));
- }
-
- @Test
- public void issueSYNCOPE418() {
- try {
- CPlainSchema failing = entityFactory.newEntity(CPlainSchema.class);
- failing.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
- failing.setType(AttrSchemaType.String);
- plainSchemaDAO.save(failing);
-
- fail();
- } catch (InvalidEntityException e) {
- assertTrue(e.hasViolation(EntityViolationType.InvalidName));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ConnInstanceTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ConnInstanceTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ConnInstanceTest.java
deleted file mode 100644
index 2395370..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ConnInstanceTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * 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.syncope.persistence.jpa.entity;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import org.apache.syncope.common.lib.types.ConnConfPropSchema;
-import org.apache.syncope.common.lib.types.ConnConfProperty;
-import org.apache.syncope.persistence.api.dao.ConnInstanceDAO;
-import org.apache.syncope.persistence.api.entity.ConnInstance;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class ConnInstanceTest extends AbstractTest {
-
- @Autowired
- private ConnInstanceDAO connInstanceDAO;
-
- @Test
- public void findAll() {
- List<ConnInstance> connectors = connInstanceDAO.findAll();
- assertNotNull(connectors);
- assertFalse(connectors.isEmpty());
- }
-
- @Test
- public void findById() {
- ConnInstance connectorInstance = connInstanceDAO.find(100L);
-
- assertNotNull("findById did not work", connectorInstance);
-
- assertEquals("invalid connector name",
- "net.tirasa.connid.bundles.soap.WebServiceConnector", connectorInstance.getConnectorName());
-
- assertEquals("invalid bundle name", "net.tirasa.connid.bundles.soap", connectorInstance.getBundleName());
- }
-
- @Test
- public void save() throws ClassNotFoundException {
- ConnInstance connInstance = entityFactory.newEntity(ConnInstance.class);
-
- connInstance.setLocation(new File(System.getProperty("java.io.tmpdir")).toURI().toString());
-
- // set connector version
- connInstance.setVersion("1.0");
-
- // set connector name
- connInstance.setConnectorName("WebService");
-
- // set bundle name
- connInstance.setBundleName("org.apache.syncope.core.persistence.test.util");
-
- connInstance.setDisplayName("New");
-
- connInstance.setConnRequestTimeout(60);
-
- // set the connector configuration using PropertyTO
- Set<ConnConfProperty> conf = new HashSet<ConnConfProperty>();
-
- ConnConfPropSchema endpointSchema = new ConnConfPropSchema();
- endpointSchema.setName("endpoint");
- endpointSchema.setType(String.class.getName());
- endpointSchema.setRequired(true);
- ConnConfProperty endpoint = new ConnConfProperty();
- endpoint.setSchema(endpointSchema);
- endpoint.getValues().add("http://host.domain");
-
- ConnConfPropSchema servicenameSchema = new ConnConfPropSchema();
- servicenameSchema.setName("servicename");
- servicenameSchema.setType(String.class.getName());
- servicenameSchema.setRequired(true);
- ConnConfProperty servicename = new ConnConfProperty();
- servicename.setSchema(servicenameSchema);
- endpoint.getValues().add("Provisioning");
-
- conf.add(endpoint);
- conf.add(servicename);
-
- // set connector configuration
- connInstance.setConfiguration(conf);
- assertFalse(connInstance.getConfiguration().isEmpty());
-
- // perform save operation
- ConnInstance actual = connInstanceDAO.save(connInstance);
-
- assertNotNull("save did not work", actual.getKey());
-
- assertTrue("save did not work", actual.getKey() > 100L);
-
- assertEquals("save did not work for \"name\" attribute", "WebService", actual.getConnectorName());
-
- assertEquals("save did not work for \"bundle name\" attribute", "org.apache.syncope.core.persistence.test.util",
- actual.getBundleName());
-
- assertEquals("save did not work for \"majorVersion\" attribute", "1.0", connInstance.getVersion());
-
- assertEquals("New", actual.getDisplayName());
-
- assertEquals(new Integer(60), actual.getConnRequestTimeout());
-
- conf = connInstance.getConfiguration();
- assertFalse(conf.isEmpty());
-
- assertNotNull("configuration retrieving failed", conf);
- assertTrue(conf.size() == 2);
- }
-
- @Test
- public void delete() {
- ConnInstance connectorInstance = connInstanceDAO.find(100L);
- assertNotNull("find to delete did not work", connectorInstance);
-
- connInstanceDAO.delete(connectorInstance.getKey());
-
- ConnInstance actual = connInstanceDAO.find(100L);
- assertNull("delete did not work", actual);
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/DerAttrTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/DerAttrTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/DerAttrTest.java
deleted file mode 100644
index 8bc4468..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/DerAttrTest.java
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * 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.syncope.persistence.jpa.entity;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-import org.apache.syncope.persistence.api.dao.DerAttrDAO;
-import org.apache.syncope.persistence.api.dao.DerSchemaDAO;
-import org.apache.syncope.persistence.api.dao.MembershipDAO;
-import org.apache.syncope.persistence.api.dao.RoleDAO;
-import org.apache.syncope.persistence.api.dao.UserDAO;
-import org.apache.syncope.persistence.api.entity.membership.MDerAttr;
-import org.apache.syncope.persistence.api.entity.membership.MDerAttrTemplate;
-import org.apache.syncope.persistence.api.entity.membership.MDerSchema;
-import org.apache.syncope.persistence.api.entity.membership.MPlainAttrValue;
-import org.apache.syncope.persistence.api.entity.membership.Membership;
-import org.apache.syncope.persistence.api.entity.role.RDerAttr;
-import org.apache.syncope.persistence.api.entity.role.RDerAttrTemplate;
-import org.apache.syncope.persistence.api.entity.role.RDerSchema;
-import org.apache.syncope.persistence.api.entity.role.RPlainAttrValue;
-import org.apache.syncope.persistence.api.entity.role.Role;
-import org.apache.syncope.persistence.api.entity.user.UDerAttr;
-import org.apache.syncope.persistence.api.entity.user.UDerSchema;
-import org.apache.syncope.persistence.api.entity.user.UPlainAttrValue;
-import org.apache.syncope.persistence.api.entity.user.User;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class DerAttrTest extends AbstractTest {
-
- @Autowired
- private DerAttrDAO derAttrDAO;
-
- @Autowired
- private UserDAO userDAO;
-
- @Autowired
- private MembershipDAO membershipDAO;
-
- @Autowired
- private RoleDAO roleDAO;
-
- @Autowired
- private DerSchemaDAO derSchemaDAO;
-
- @Test
- public void findAll() {
- List<UDerAttr> list = derAttrDAO.findAll(UDerAttr.class);
- assertEquals("did not get expected number of derived attributes ", 2, list.size());
- }
-
- @Test
- public void findById() {
- UDerAttr attribute = derAttrDAO.find(100L, UDerAttr.class);
- assertNotNull("did not find expected attribute schema", attribute);
- }
-
- @Test
- public void saveUDerAttribute() {
- UDerSchema cnSchema = derSchemaDAO.find("cn", UDerSchema.class);
- assertNotNull(cnSchema);
-
- User owner = userDAO.find(3L);
- assertNotNull("did not get expected user", owner);
-
- UDerAttr derAttr = entityFactory.newEntity(UDerAttr.class);
- derAttr.setOwner(owner);
- derAttr.setSchema(cnSchema);
-
- derAttr = derAttrDAO.save(derAttr);
-
- UDerAttr actual = derAttrDAO.find(derAttr.getKey(), UDerAttr.class);
- assertNotNull("expected save to work", actual);
- assertEquals(derAttr, actual);
-
- UPlainAttrValue firstname = owner.getPlainAttr("firstname").getValues().iterator().next();
- UPlainAttrValue surname = owner.getPlainAttr("surname").getValues().iterator().next();
-
- assertEquals(surname.getValue() + ", " + firstname.getValue(), derAttr.getValue(owner.getPlainAttrs()));
- }
-
- @Test
- public void saveMDerAttribute() {
- Membership owner = membershipDAO.find(1L);
- assertNotNull("did not get expected user", owner);
-
- MDerAttr derAttr = entityFactory.newEntity(MDerAttr.class);
- derAttr.setOwner(owner);
- derAttr.setTemplate(owner.getRole().getAttrTemplate(MDerAttrTemplate.class, "mderiveddata"));
-
- derAttr = derAttrDAO.save(derAttr);
- assertNotNull(derAttr.getTemplate());
-
- MDerAttr actual = derAttrDAO.find(derAttr.getKey(), MDerAttr.class);
- assertNotNull("expected save to work", actual);
- assertEquals(derAttr, actual);
-
- MPlainAttrValue sx = owner.getPlainAttr("mderived_sx").getValues().iterator().next();
- MPlainAttrValue dx = owner.getPlainAttr("mderived_dx").getValues().iterator().next();
-
- assertEquals(sx.getValue() + "-" + dx.getValue(), derAttr.getValue(owner.getPlainAttrs()));
- }
-
- @Test
- public void saveRDerAttribute() {
- Role owner = roleDAO.find(1L);
- assertNotNull("did not get expected user", owner);
-
- RDerAttr derAttr = entityFactory.newEntity(RDerAttr.class);
- derAttr.setOwner(owner);
- derAttr.setTemplate(owner.getAttrTemplate(RDerAttrTemplate.class, "rderiveddata"));
-
- derAttr = derAttrDAO.save(derAttr);
- assertNotNull(derAttr.getTemplate());
-
- RDerAttr actual = derAttrDAO.find(derAttr.getKey(), RDerAttr.class);
- assertNotNull("expected save to work", actual);
- assertEquals(derAttr, actual);
-
- RPlainAttrValue sx = owner.getPlainAttr("rderived_sx").getValues().iterator().next();
- RPlainAttrValue dx = owner.getPlainAttr("rderived_dx").getValues().iterator().next();
-
- assertEquals(sx.getValue() + "-" + dx.getValue(), derAttr.getValue(owner.getPlainAttrs()));
- }
-
- @Test
- public void delete() {
- UDerAttr attribute = derAttrDAO.find(100L, UDerAttr.class);
- String attributeSchemaName = attribute.getSchema().getKey();
-
- derAttrDAO.delete(attribute.getKey(), UDerAttr.class);
-
- UDerAttr actual = derAttrDAO.find(100L, UDerAttr.class);
- assertNull("delete did not work", actual);
-
- UDerSchema attributeSchema = derSchemaDAO.find(attributeSchemaName, UDerSchema.class);
- assertNotNull("user derived attribute schema deleted " + "when deleting values", attributeSchema);
- }
-
- @Test
- public void issueSYNCOPE134User() {
- UDerSchema sderived = entityFactory.newEntity(UDerSchema.class);
- sderived.setKey("sderived");
- sderived.setExpression("status + ' - ' + username + ' - ' + creationDate + '[' + failedLogins + ']'");
-
- sderived = derSchemaDAO.save(sderived);
- derSchemaDAO.flush();
-
- UDerSchema actual = derSchemaDAO.find("sderived", UDerSchema.class);
- assertNotNull("expected save to work", actual);
- assertEquals(sderived, actual);
-
- User owner = userDAO.find(3L);
- assertNotNull("did not get expected user", owner);
-
- UDerAttr derAttr = entityFactory.newEntity(UDerAttr.class);
- derAttr.setOwner(owner);
- derAttr.setSchema(sderived);
-
- derAttr = derAttrDAO.save(derAttr);
- derAttrDAO.flush();
-
- derAttr = derAttrDAO.find(derAttr.getKey(), UDerAttr.class);
- assertNotNull("expected save to work", derAttr);
-
- String value = derAttr.getValue(owner.getPlainAttrs());
- assertNotNull(value);
- assertFalse(value.isEmpty());
- assertTrue(value.startsWith("active - vivaldi - 2010-10-20"));
- assertTrue(value.endsWith("[0]"));
- }
-
- @Test
- public void issueSYNCOPE134Role() {
- RDerSchema sderived = entityFactory.newEntity(RDerSchema.class);
- sderived.setKey("sderived");
- sderived.setExpression("name");
-
- sderived = derSchemaDAO.save(sderived);
- derSchemaDAO.flush();
-
- RDerSchema actual = derSchemaDAO.find("sderived", RDerSchema.class);
- assertNotNull("expected save to work", actual);
- assertEquals(sderived, actual);
-
- Role owner = roleDAO.find(7L);
- assertNotNull("did not get expected role", owner);
-
- RDerAttrTemplate template = entityFactory.newEntity(RDerAttrTemplate.class);
- template.setSchema(sderived);
- owner.getAttrTemplates(RDerAttrTemplate.class).add(template);
-
- RDerAttr derAttr = entityFactory.newEntity(RDerAttr.class);
- derAttr.setOwner(owner);
- derAttr.setTemplate(owner.getAttrTemplate(RDerAttrTemplate.class, sderived.getKey()));
-
- derAttr = derAttrDAO.save(derAttr);
- assertNotNull(derAttr.getTemplate());
- derAttrDAO.flush();
-
- derAttr = derAttrDAO.find(derAttr.getKey(), RDerAttr.class);
- assertNotNull("expected save to work", derAttr);
-
- String value = derAttr.getValue(owner.getPlainAttrs());
- assertNotNull(value);
- assertFalse(value.isEmpty());
- assertTrue(value.startsWith("managingDirector"));
- }
-
- @Test
- public void issueSYNCOPE134Memb() {
- MDerSchema mderived = entityFactory.newEntity(MDerSchema.class);
- mderived.setKey("mderived");
- mderived.setExpression("key");
-
- mderived = derSchemaDAO.save(mderived);
- derSchemaDAO.flush();
-
- MDerSchema actual = derSchemaDAO.find("mderived", MDerSchema.class);
- assertNotNull("expected save to work", actual);
- assertEquals(mderived, actual);
-
- Membership owner = membershipDAO.find(4L);
- assertNotNull("did not get expected membership", owner);
-
- MDerAttrTemplate template = entityFactory.newEntity(MDerAttrTemplate.class);
- template.setSchema(mderived);
- owner.getRole().getAttrTemplates(MDerAttrTemplate.class).add(template);
-
- derSchemaDAO.flush();
-
- MDerAttr derAttr = entityFactory.newEntity(MDerAttr.class);
- derAttr.setOwner(owner);
- derAttr.setTemplate(owner.getRole().getAttrTemplate(MDerAttrTemplate.class, mderived.getKey()));
-
- derAttr = derAttrDAO.save(derAttr);
- assertNotNull(derAttr.getTemplate());
- derAttrDAO.flush();
-
- derAttr = derAttrDAO.find(derAttr.getKey(), MDerAttr.class);
- assertNotNull("expected save to work", derAttr);
-
- String value = derAttr.getValue(owner.getPlainAttrs());
- assertNotNull(value);
- assertFalse(value.isEmpty());
- assertTrue(value.equalsIgnoreCase("4"));
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/DerSchemaTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/DerSchemaTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/DerSchemaTest.java
deleted file mode 100644
index 94c61aa..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/DerSchemaTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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.syncope.persistence.jpa.entity;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.List;
-import org.apache.syncope.common.lib.types.AttributableType;
-import org.apache.syncope.common.lib.types.EntityViolationType;
-import org.apache.syncope.persistence.api.attrvalue.validation.InvalidEntityException;
-import org.apache.syncope.persistence.api.dao.DerSchemaDAO;
-import org.apache.syncope.persistence.api.entity.DerSchema;
-import org.apache.syncope.persistence.api.entity.role.RDerSchema;
-import org.apache.syncope.persistence.api.entity.user.UDerSchema;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class DerSchemaTest extends AbstractTest {
-
- @Autowired
- private DerSchemaDAO derSchemaDAO;
-
- @Test
- public void findAll() {
- List<UDerSchema> list = derSchemaDAO.findAll(UDerSchema.class);
- assertEquals(3, list.size());
- }
-
- @Test
- public void findByName() {
- UDerSchema attributeSchema = derSchemaDAO.find("cn", UDerSchema.class);
- assertNotNull("did not find expected derived attribute schema", attributeSchema);
- }
-
- @Test
- public void save() {
- UDerSchema derivedAttributeSchema = entityFactory.newEntity(UDerSchema.class);
- derivedAttributeSchema.setKey("cn2");
- derivedAttributeSchema.setExpression("firstname surname");
-
- derSchemaDAO.save(derivedAttributeSchema);
-
- UDerSchema actual = derSchemaDAO.find("cn2", UDerSchema.class);
- assertNotNull("expected save to work", actual);
- assertEquals(derivedAttributeSchema, actual);
- }
-
- @Test
- public void delete() {
- UDerSchema cn = derSchemaDAO.find("cn", UDerSchema.class);
- assertNotNull(cn);
-
- derSchemaDAO.delete(cn.getKey(), attrUtilFactory.getInstance(AttributableType.USER));
-
- DerSchema actual = derSchemaDAO.find("cn", UDerSchema.class);
- assertNull("delete did not work", actual);
-
- // ------------- //
- RDerSchema rderiveddata = derSchemaDAO.find("rderiveddata", RDerSchema.class);
- assertNotNull(rderiveddata);
-
- derSchemaDAO.delete(rderiveddata.getKey(), attrUtilFactory.getInstance(AttributableType.ROLE));
-
- actual = derSchemaDAO.find("rderiveddata", RDerSchema.class);
- assertNull("delete did not work", actual);
- }
-
- @Test
- public void issueSYNCOPE418() {
- UDerSchema schema = entityFactory.newEntity(UDerSchema.class);
- schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
-
- try {
- derSchemaDAO.save(schema);
- fail();
- } catch (InvalidEntityException e) {
- assertTrue(e.hasViolation(EntityViolationType.InvalidName));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/EntitlementTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/EntitlementTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/EntitlementTest.java
deleted file mode 100644
index 9d4746b..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/EntitlementTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.syncope.persistence.jpa.entity;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.util.List;
-import org.apache.syncope.persistence.api.dao.EntitlementDAO;
-import org.apache.syncope.persistence.api.entity.Entitlement;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class EntitlementTest extends AbstractTest {
-
- @Autowired
- private EntitlementDAO entitlementDAO;
-
- @Test
- public void findAll() {
- List<Entitlement> list = entitlementDAO.findAll();
- assertEquals("did not get expected number of entitlements ", 86, list.size());
- }
-
- @Test
- public void findByName() {
- Entitlement entitlement = entitlementDAO.find("base");
- assertNotNull("did not find expected entitlement", entitlement);
- }
-
- @Test
- public void save() {
- Entitlement entitlement = entityFactory.newEntity(Entitlement.class);
- entitlement.setKey("another");
-
- entitlementDAO.save(entitlement);
-
- Entitlement actual = entitlementDAO.find("another");
- assertNotNull("expected save to work", actual);
- assertEquals(entitlement, actual);
- }
-
- @Test
- public void delete() {
- Entitlement entitlement = entitlementDAO.find("base");
- assertNotNull("did not find expected entitlement", entitlement);
-
- entitlementDAO.delete("base");
-
- assertNull(entitlementDAO.find("base"));
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/MembershipTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/MembershipTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/MembershipTest.java
deleted file mode 100644
index b83c453..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/MembershipTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.syncope.persistence.jpa.entity;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.util.List;
-import org.apache.syncope.persistence.api.dao.MembershipDAO;
-import org.apache.syncope.persistence.api.dao.RoleDAO;
-import org.apache.syncope.persistence.api.dao.UserDAO;
-import org.apache.syncope.persistence.api.entity.membership.Membership;
-import org.apache.syncope.persistence.api.entity.role.Role;
-import org.apache.syncope.persistence.api.entity.user.User;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class MembershipTest extends AbstractTest {
-
- @Autowired
- private MembershipDAO membershipDAO;
-
- @Autowired
- private UserDAO userDAO;
-
- @Autowired
- private RoleDAO roleDAO;
-
- @Test
- public void findAll() {
- List<Membership> list = membershipDAO.findAll();
- assertEquals(7, list.size());
- }
-
- @Test
- public void find() {
- Membership membership = membershipDAO.find(1L);
- assertNotNull("did not find expected membership", membership);
- }
-
- @Test
- public void save() {
- User user = userDAO.find(4L);
- Role role = roleDAO.find(1L);
-
- Membership membership = entityFactory.newEntity(Membership.class);
- membership.setUser(user);
- membership.setRole(role);
-
- membership = membershipDAO.save(membership);
-
- Membership actual = membershipDAO.find(membership.getKey());
- assertNotNull("expected save to work", actual);
- }
-
- @Test
- public void delete() {
- Membership membership = membershipDAO.find(4L);
- membershipDAO.delete(membership.getKey());
-
- Membership actual = membershipDAO.find(4L);
- assertNull("delete did not work", actual);
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/NotificationTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/NotificationTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/NotificationTest.java
deleted file mode 100644
index cd4b116..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/NotificationTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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.syncope.persistence.jpa.entity;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.util.List;
-import org.apache.syncope.common.lib.types.IntMappingType;
-import org.apache.syncope.persistence.api.dao.NotificationDAO;
-import org.apache.syncope.persistence.api.entity.Notification;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class NotificationTest extends AbstractTest {
-
- @Autowired
- private NotificationDAO notificationDAO;
-
- @Test
- public void find() {
- Notification notification = notificationDAO.find(10L);
- assertNotNull(notification);
- assertNotNull(notification.getEvents());
- assertFalse(notification.getEvents().isEmpty());
- assertNotNull(notification.getUserAbout());
- assertNotNull(notification.getRecipients());
-
- }
-
- @Test
- public void findAll() {
- List<Notification> notifications = notificationDAO.findAll();
- assertNotNull(notifications);
- assertFalse(notifications.isEmpty());
- }
-
- @Test
- public void save() {
- Notification notification = entityFactory.newEntity(Notification.class);
- notification.addEvent("save");
-
- notification.setUserAbout("fake search condition");
-
- notification.setRecipients("fake search condition");
-
- notification.setRecipientAttrName("email");
- notification.setRecipientAttrType(IntMappingType.UserSchema);
-
- notification.setSender("syncope@syncope.apache.org");
- notification.setSubject("Test notification");
- notification.setTemplate("test");
-
- Notification actual = notificationDAO.save(notification);
- assertNotNull(actual);
- assertNotNull(actual.getKey());
- }
-
- @Test
- public void delete() {
- notificationDAO.delete(10L);
- assertNull(notificationDAO.find(10L));
- }
-
- @Test
- public void issueSYNCOPE445() {
- Notification notification = entityFactory.newEntity(Notification.class);
- notification.addEvent("save");
-
- notification.setUserAbout("fake search condition");
-
- notification.setRecipients("fake search condition");
-
- notification.setRecipientAttrName("email");
- notification.setRecipientAttrType(IntMappingType.UserSchema);
-
- notification.addStaticRecipient("syncope445@syncope.apache.org");
-
- notification.setSender("syncope@syncope.apache.org");
- notification.setSubject("Test notification");
- notification.setTemplate("test");
-
- Notification actual = notificationDAO.save(notification);
- assertNotNull(actual);
- assertNotNull(actual.getKey());
- assertNotNull(actual.getStaticRecipients());
- assertFalse(actual.getStaticRecipients().isEmpty());
- }
-
- @Test
- public void issueSYNCOPE446() {
- Notification notification = entityFactory.newEntity(Notification.class);
- notification.addEvent("[REST]:[RoleController]:[]:[create]:[SUCCESS]");
-
- notification.setRoleAbout("fake search condition");
-
- notification.setRecipientAttrName("email");
- notification.setRecipientAttrType(IntMappingType.UserSchema);
-
- notification.addStaticRecipient("syncope446@syncope.apache.org");
-
- notification.setSender("syncope@syncope.apache.org");
- notification.setSubject("Test notification");
- notification.setTemplate("test");
-
- Notification actual = notificationDAO.save(notification);
- assertNotNull(actual);
- assertNotNull(actual.getKey());
- assertNotNull(actual.getStaticRecipients());
- assertFalse(actual.getStaticRecipients().isEmpty());
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/PlainSchemaTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/PlainSchemaTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/PlainSchemaTest.java
deleted file mode 100644
index 652d32e..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/PlainSchemaTest.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * 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.syncope.persistence.jpa.entity;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.List;
-import org.apache.syncope.common.lib.SyncopeConstants;
-import org.apache.syncope.common.lib.types.AttrSchemaType;
-import org.apache.syncope.common.lib.types.AttributableType;
-import org.apache.syncope.common.lib.types.EntityViolationType;
-import org.apache.syncope.persistence.api.attrvalue.validation.InvalidEntityException;
-import org.apache.syncope.persistence.api.dao.PlainSchemaDAO;
-import org.apache.syncope.persistence.api.entity.role.RPlainAttr;
-import org.apache.syncope.persistence.api.entity.role.RPlainSchema;
-import org.apache.syncope.persistence.api.entity.user.UPlainSchema;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class PlainSchemaTest extends AbstractTest {
-
- @Autowired
- private PlainSchemaDAO plainSchemaDAO;
-
- @Test
- public void findAll() {
- List<UPlainSchema> userList = plainSchemaDAO.findAll(UPlainSchema.class);
- assertEquals(15, userList.size());
-
- List<RPlainSchema> roleList = plainSchemaDAO.findAll(RPlainSchema.class);
- assertEquals(5, roleList.size());
- }
-
- @Test
- public void findByName() {
- UPlainSchema schema = plainSchemaDAO.find("fullname", UPlainSchema.class);
- assertNotNull("did not find expected attribute schema", schema);
- }
-
- @Test
- public void findAttrs() {
- List<RPlainSchema> schemas = plainSchemaDAO.findAll(RPlainSchema.class);
- assertNotNull(schemas);
- assertFalse(schemas.isEmpty());
-
- for (RPlainSchema schema : schemas) {
- List<RPlainAttr> attrs = plainSchemaDAO.findAttrs(schema, RPlainAttr.class);
- assertNotNull(attrs);
- assertFalse(attrs.isEmpty());
- }
- }
-
- @Test
- public void save() {
- UPlainSchema schema = entityFactory.newEntity(UPlainSchema.class);
- schema.setKey("secondaryEmail");
- schema.setType(AttrSchemaType.String);
- schema.setValidatorClass("org.apache.syncope.core.validation.EmailAddressValidator");
- schema.setMandatoryCondition("false");
- schema.setMultivalue(true);
-
- plainSchemaDAO.save(schema);
-
- UPlainSchema actual = plainSchemaDAO.find("secondaryEmail", UPlainSchema.class);
- assertNotNull("expected save to work", actual);
- assertEquals(schema, actual);
- }
-
- @Test(expected = InvalidEntityException.class)
- public void saveNonValid() {
- UPlainSchema schema = entityFactory.newEntity(UPlainSchema.class);
- schema.setKey("secondaryEmail");
- schema.setType(AttrSchemaType.String);
- schema.setValidatorClass("org.apache.syncope.core.validation.EmailAddressValidator");
- schema.setMandatoryCondition("false");
- schema.setMultivalue(true);
- schema.setUniqueConstraint(true);
-
- plainSchemaDAO.save(schema);
- }
-
- @Test
- public void checkForEnumType() {
- RPlainSchema schema = entityFactory.newEntity(RPlainSchema.class);
- schema.setType(AttrSchemaType.Enum);
- schema.setKey("color");
-
- Exception ex = null;
- try {
- plainSchemaDAO.save(schema);
- } catch (Exception e) {
- ex = e;
- }
- assertNotNull(ex);
-
- schema.setEnumerationValues("red" + SyncopeConstants.ENUM_VALUES_SEPARATOR + "yellow");
- schema.setEnumerationKeys("1" + SyncopeConstants.ENUM_VALUES_SEPARATOR + "2");
-
- plainSchemaDAO.save(schema);
-
- RPlainSchema actual = plainSchemaDAO.find(schema.getKey(), RPlainSchema.class);
- assertNotNull(actual);
- assertNotNull(actual.getEnumerationKeys());
- assertFalse(actual.getEnumerationKeys().isEmpty());
- }
-
- @Test(expected = InvalidEntityException.class)
- public void saveInvalidSchema() {
- UPlainSchema schema = entityFactory.newEntity(UPlainSchema.class);
- schema.setKey("username");
- plainSchemaDAO.save(schema);
- }
-
- @Test
- public void delete() {
- UPlainSchema fullnam = plainSchemaDAO.find("fullname", UPlainSchema.class);
-
- plainSchemaDAO.delete(fullnam.getKey(), attrUtilFactory.getInstance(AttributableType.USER));
-
- UPlainSchema actual = plainSchemaDAO.find("fullname", UPlainSchema.class);
- assertNull("delete did not work", actual);
- }
-
- @Test
- public void issueSYNCOPE418() {
- UPlainSchema schema = entityFactory.newEntity(UPlainSchema.class);
- schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
-
- try {
- plainSchemaDAO.save(schema);
- fail();
- } catch (InvalidEntityException e) {
- assertTrue(e.hasViolation(EntityViolationType.InvalidName));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/PolicyTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/PolicyTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/PolicyTest.java
deleted file mode 100644
index 8c1d65a..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/PolicyTest.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * 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.syncope.persistence.jpa.entity;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.util.List;
-import org.apache.syncope.common.lib.types.PasswordPolicySpec;
-import org.apache.syncope.common.lib.types.PolicyType;
-import org.apache.syncope.common.lib.types.SyncPolicySpec;
-import org.apache.syncope.persistence.api.attrvalue.validation.InvalidEntityException;
-import org.apache.syncope.persistence.api.dao.PolicyDAO;
-import org.apache.syncope.persistence.api.entity.PasswordPolicy;
-import org.apache.syncope.persistence.api.entity.Policy;
-import org.apache.syncope.persistence.api.entity.SyncPolicy;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class PolicyTest extends AbstractTest {
-
- @Autowired
- private PolicyDAO policyDAO;
-
- @Test
- public void findAll() {
- List<Policy> policies = policyDAO.findAll();
- assertNotNull(policies);
- assertFalse(policies.isEmpty());
- }
-
- @Test
- public void findById() {
- Policy policy = policyDAO.find(1L);
- assertNotNull("findById did not work", policy);
- }
-
- @Test
- public void findByType() {
- List<? extends Policy> policies = policyDAO.find(PolicyType.SYNC);
- assertNotNull("findById did not work", policies);
- assertFalse(policies.isEmpty());
- }
-
- @Test
- public void findGlobalPasswordPolicy() {
- PasswordPolicy policy = policyDAO.getGlobalPasswordPolicy();
- assertNotNull("findById did not work", policy);
-
- assertEquals(PolicyType.GLOBAL_PASSWORD, policy.getType());
-
- assertEquals("invalid policy values", 8, (policy.getSpecification(PasswordPolicySpec.class)).getMinLength());
- }
-
- @Test(expected = InvalidEntityException.class)
- public void saveInvalidPolicy() {
- PasswordPolicySpec passwordPolicy = new PasswordPolicySpec();
- passwordPolicy.setMaxLength(8);
- passwordPolicy.setMinLength(6);
-
- SyncPolicy policy = entityFactory.newPolicy(SyncPolicy.class, false);
- policy.setSpecification(passwordPolicy);
- policy.setDescription("sync policy");
-
- policyDAO.save(policy);
- }
-
- @Test(expected = InvalidEntityException.class)
- public void saveSecondPasswordPolicy() {
- PasswordPolicySpec passwordPolicy = new PasswordPolicySpec();
- passwordPolicy.setMaxLength(8);
- passwordPolicy.setMinLength(6);
-
- PasswordPolicy policy = entityFactory.newPolicy(PasswordPolicy.class, true);
- policy.setSpecification(passwordPolicy);
- policy.setDescription("global password policy");
-
- policyDAO.save(policy);
- }
-
- @Test
- public void create() {
- SyncPolicy policy = entityFactory.newPolicy(SyncPolicy.class, false);
-
- final String syncURuleName = "net.tirasa.sync.correlation.TirasaURule";
- final String syncRRuleName = "net.tirasa.sync.correlation.TirasaRRule";
-
- SyncPolicySpec syncPolicySpec = new SyncPolicySpec();
- syncPolicySpec.setUserJavaRule(syncURuleName);
- syncPolicySpec.setRoleJavaRule(syncRRuleName);
-
- policy.setSpecification(syncPolicySpec);
- policy.setDescription("Sync policy");
-
- policy = policyDAO.save(policy);
-
- assertNotNull(policy);
- assertEquals(PolicyType.SYNC, policy.getType());
- assertEquals(syncURuleName, (policy.getSpecification(SyncPolicySpec.class)).getUserJavaRule());
- assertEquals(syncRRuleName, (policy.getSpecification(SyncPolicySpec.class)).getRoleJavaRule());
- }
-
- @Test
- public void update() {
- PasswordPolicySpec specification = new PasswordPolicySpec();
- specification.setMaxLength(8);
- specification.setMinLength(6);
-
- Policy policy = policyDAO.getGlobalPasswordPolicy();
- assertNotNull(policy);
- policy.setSpecification(specification);
-
- policy = policyDAO.save(policy);
-
- assertNotNull(policy);
- assertEquals(PolicyType.GLOBAL_PASSWORD, policy.getType());
- assertEquals((policy.getSpecification(PasswordPolicySpec.class)).getMaxLength(), 8);
- assertEquals((policy.getSpecification(PasswordPolicySpec.class)).getMinLength(), 6);
- }
-
- @Test
- public void delete() {
- Policy policy = policyDAO.find(1L);
- assertNotNull("find to delete did not work", policy);
-
- policyDAO.delete(policy);
-
- Policy actual = policyDAO.find(1L);
- assertNull("delete did not work", actual);
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ReportTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ReportTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ReportTest.java
deleted file mode 100644
index e469f5c..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ReportTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.syncope.persistence.jpa.entity;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.util.List;
-import org.apache.syncope.common.lib.report.UserReportletConf;
-import org.apache.syncope.persistence.api.dao.ReportDAO;
-import org.apache.syncope.persistence.api.entity.Report;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class ReportTest extends AbstractTest {
-
- @Autowired
- private ReportDAO reportDAO;
-
- @Test
- public void find() {
- Report report = reportDAO.find(1L);
- assertNotNull(report);
-
- report = reportDAO.find(10L);
- assertNull(report);
- }
-
- @Test
- public void findAll() {
- List<Report> reports = reportDAO.findAll();
- assertNotNull(reports);
- assertEquals(1, reports.size());
- }
-
- @Test
- public void save() {
- int beforeCount = reportDAO.count();
-
- Report report = entityFactory.newEntity(Report.class);
- report.setName("new report");
- report.addReportletConf(new UserReportletConf("first"));
- report.addReportletConf(new UserReportletConf("second"));
-
- report = reportDAO.save(report);
- assertNotNull(report);
- assertNotNull(report.getKey());
-
- int afterCount = reportDAO.count();
- assertEquals(afterCount, beforeCount + 1);
- }
-
- @Test
- public void delete() {
- Report report = reportDAO.find(1L);
- assertNotNull(report);
-
- reportDAO.delete(1L);
-
- report = reportDAO.find(1L);
- assertNull(report);
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ResourceTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ResourceTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ResourceTest.java
deleted file mode 100644
index a82c450..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/entity/ResourceTest.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * 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.syncope.persistence.jpa.entity;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.syncope.common.lib.types.AttributableType;
-import org.apache.syncope.common.lib.types.EntityViolationType;
-import org.apache.syncope.common.lib.types.IntMappingType;
-import org.apache.syncope.common.lib.types.MappingPurpose;
-import org.apache.syncope.persistence.api.attrvalue.validation.InvalidEntityException;
-import org.apache.syncope.persistence.api.dao.ExternalResourceDAO;
-import org.apache.syncope.persistence.api.entity.ConnInstance;
-import org.apache.syncope.persistence.api.entity.ExternalResource;
-import org.apache.syncope.persistence.api.entity.user.UMapping;
-import org.apache.syncope.persistence.api.entity.user.UMappingItem;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class ResourceTest extends AbstractTest {
-
- @Autowired
- private ExternalResourceDAO resourceDAO;
-
- @Test
- public void findById() {
- ExternalResource resource = resourceDAO.find("ws-target-resource-1");
- assertNotNull("findById did not work", resource);
-
- ConnInstance connector = resource.getConnector();
- assertNotNull("connector not found", connector);
- assertEquals("invalid connector name",
- "net.tirasa.connid.bundles.soap.WebServiceConnector", connector.getConnectorName());
- assertEquals("invalid bundle name", "net.tirasa.connid.bundles.soap", connector.getBundleName());
-
- assertFalse("no mapping specified", resource.getUmapping().getItems().isEmpty());
-
- List<Long> mappingIds = new ArrayList<>();
- for (UMappingItem item : resource.getUmapping().getItems()) {
- mappingIds.add(item.getKey());
- }
- assertTrue(mappingIds.contains(100L));
- }
-
- @Test
- public void findAll() {
- List<ExternalResource> resources = resourceDAO.findAll();
- assertNotNull(resources);
- assertEquals(18, resources.size());
- }
-
- @Test
- public void findAllByPriority() {
- List<ExternalResource> resources = resourceDAO.findAllByPriority();
- assertNotNull(resources);
- assertFalse(resources.isEmpty());
- }
-
- @Test
- public void getAccountId() {
- ExternalResource resource = resourceDAO.find("ws-target-resource-2");
- assertNotNull(resource);
- assertEquals("fullname", resource.getUmapping().getAccountIdItem().getIntAttrName());
- }
-
- @Test
- public void save() {
- ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
- resource.setKey("ws-target-resource-basic-save");
- resource.setPropagationPriority(2);
- resource.setPropagationPrimary(true);
-
- UMapping mapping = entityFactory.newEntity(UMapping.class);
- resource.setUmapping(mapping);
-
- UMappingItem accountId = entityFactory.newEntity(UMappingItem.class);
- accountId.setExtAttrName("username");
- accountId.setIntAttrName("fullname");
- accountId.setIntMappingType(IntMappingType.UserId);
- accountId.setPurpose(MappingPurpose.BOTH);
- mapping.setAccountIdItem(accountId);
-
- ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
- resource.setConnector(connector);
-
- // save the resource
- ExternalResource actual = resourceDAO.save(resource);
-
- assertNotNull(actual);
- assertNotNull(actual.getConnector());
- assertNotNull(actual.getUmapping());
- assertFalse(actual.getUmapping().getItems().isEmpty());
- assertEquals(Integer.valueOf(2), actual.getPropagationPriority());
- assertTrue(actual.isPropagationPrimary());
- }
-
- @Test(expected = InvalidEntityException.class)
- public void saveInvalidMappingIntAttr() {
- ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
- resource.setKey("ws-target-resource-basic-save-invalid");
-
- ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
- resource.setConnector(connector);
-
- UMapping mapping = entityFactory.newEntity(UMapping.class);
- resource.setUmapping(mapping);
-
- UMappingItem accountId = entityFactory.newEntity(UMappingItem.class);
- accountId.setAccountid(true);
- accountId.setIntMappingType(IntMappingType.UserSchema);
- mapping.addItem(accountId);
-
- // save the resource
- ExternalResource actual = resourceDAO.save(resource);
- assertNotNull(actual);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void saveInvalidAccountIdMapping() {
- ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
- resource.setKey("ws-target-resource-basic-save-invalid");
-
- ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
- resource.setConnector(connector);
-
- UMapping mapping = entityFactory.newEntity(UMapping.class);
- resource.setUmapping(mapping);
-
- UMappingItem accountId = entityFactory.newEntity(UMappingItem.class);
- accountId.setAccountid(true);
- accountId.setIntMappingType(IntMappingType.UserVirtualSchema);
- mapping.setAccountIdItem(accountId);
-
- // save the resource
- ExternalResource actual = resourceDAO.save(resource);
- assertNotNull(actual);
- }
-
- @Test(expected = InvalidEntityException.class)
- public void saveInvalidMappingExtAttr() {
- ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
- resource.setKey("ws-target-resource-basic-save-invalid");
-
- ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
- resource.setConnector(connector);
-
- UMapping mapping = entityFactory.newEntity(UMapping.class);
- resource.setUmapping(mapping);
-
- UMappingItem item = entityFactory.newEntity(UMappingItem.class);
- item.setAccountid(true);
- item.setIntAttrName("fullname");
- item.setIntMappingType(IntMappingType.UserSchema);
- mapping.addItem(item);
-
- item = entityFactory.newEntity(UMappingItem.class);
- item.setIntAttrName("userId");
- item.setIntMappingType(IntMappingType.UserSchema);
- mapping.addItem(item);
-
- ExternalResource actual = resourceDAO.save(resource);
- assertNotNull(actual);
- }
-
- @Test
- public void saveWithRoleMappingType() {
- ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
- resource.setKey("ws-target-resource-basic-save-invalid");
-
- ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
- resource.setConnector(connector);
-
- UMapping mapping = entityFactory.newEntity(UMapping.class);
- resource.setUmapping(mapping);
-
- UMappingItem item = entityFactory.newEntity(UMappingItem.class);
- item.setIntAttrName("fullname");
- item.setExtAttrName("fullname");
- item.setIntMappingType(IntMappingType.UserSchema);
- item.setPurpose(MappingPurpose.BOTH);
- mapping.setAccountIdItem(item);
-
- item = entityFactory.newEntity(UMappingItem.class);
- item.setIntAttrName("icon");
- item.setExtAttrName("icon");
- item.setIntMappingType(IntMappingType.RoleSchema);
- item.setPurpose(MappingPurpose.BOTH);
- mapping.addItem(item);
-
- item = entityFactory.newEntity(UMappingItem.class);
- item.setIntAttrName("mderiveddata");
- item.setExtAttrName("mderiveddata");
- item.setIntMappingType(IntMappingType.MembershipDerivedSchema);
- item.setPurpose(MappingPurpose.BOTH);
- mapping.addItem(item);
-
- // save the resource
- ExternalResource actual = resourceDAO.save(resource);
- assertNotNull(actual);
-
- int items = 0;
- for (UMappingItem mapItem : actual.getUmapping().getItems()) {
- items++;
-
- if ("icon".equals(mapItem.getIntAttrName())) {
- assertTrue(IntMappingType.contains(AttributableType.ROLE,
- mapItem.getIntMappingType().toString()));
- }
- if ("mderiveddata".equals(mapItem.getIntAttrName())) {
- assertTrue(IntMappingType.contains(AttributableType.MEMBERSHIP,
- mapItem.getIntMappingType().toString()));
- }
- }
- assertEquals(3, items);
- }
-
- @Test
- public void delete() {
- ExternalResource resource = resourceDAO.find("ws-target-resource-2");
- assertNotNull(resource);
-
- resourceDAO.delete(resource.getKey());
-
- ExternalResource actual = resourceDAO.find("ws-target-resource-2");
- assertNull(actual);
- }
-
- @Test
- public void issueSYNCOPE418() {
- ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
- resource.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
-
- try {
- resourceDAO.save(resource);
- fail();
- } catch (InvalidEntityException e) {
- assertTrue(e.hasViolation(EntityViolationType.InvalidName));
- }
- }
-}