Search in sources :

Example 16 with SmartExceptionDTO

use of com.runwaysdk.business.SmartExceptionDTO in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testGetAllCR.

@Test
public void testGetAllCR() {
    createTestChangeRequest(CreateGeoObjectAction.CLASS);
    createTestChangeRequest(UpdateAttributeAction.CLASS);
    TestUserInfo[] allowedUsers = new TestUserInfo[] { FastTestDataset.USER_ADMIN, FastTestDataset.USER_CGOV_RA, FastTestDataset.USER_CGOV_RM, FastTestDataset.USER_CGOV_RC, FastTestDataset.USER_CGOV_AC };
    for (TestUserInfo user : allowedUsers) {
        try {
            FastTestDataset.runAsUser(user, (request, adapter) -> {
                testGetAllCR(request, true);
            });
        } catch (SmartExceptionDTO e) {
            e.printStackTrace();
            Assert.fail("Unexpected permission exception was thrown on user [" + user.getUsername() + "].");
        }
    }
    TestUserInfo[] disAllowedUsers = new TestUserInfo[] { FastTestDataset.USER_MOHA_RA, FastTestDataset.USER_MOHA_RM, FastTestDataset.USER_MOHA_RC, FastTestDataset.USER_MOHA_AC };
    for (TestUserInfo user : disAllowedUsers) {
        try {
            FastTestDataset.runAsUser(user, (request, adapter) -> {
                testGetAllCR(request, false);
            });
        } catch (SmartExceptionDTO e) {
            e.printStackTrace();
            Assert.fail("Unexpected permission exception was thrown on user [" + user.getUsername() + "].");
        }
    }
}
Also used : TestUserInfo(net.geoprism.registry.test.TestUserInfo) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) Test(org.junit.Test)

Example 17 with SmartExceptionDTO

use of com.runwaysdk.business.SmartExceptionDTO in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testSetActionStatus.

@Test
public void testSetActionStatus() {
    String serializedCR = createTestChangeRequest(UpdateAttributeAction.CLASS);
    TestUserInfo[] allowedUsers = new TestUserInfo[] { FastTestDataset.USER_ADMIN, FastTestDataset.USER_CGOV_RA, FastTestDataset.USER_CGOV_RM };
    for (TestUserInfo user : allowedUsers) {
        try {
            FastTestDataset.runAsUser(user, (request, adapter) -> {
                testSetActionStatus(request, serializedCR);
            });
        } catch (SmartExceptionDTO e) {
            e.printStackTrace();
            Assert.fail("Unexpected permission exception was thrown on user [" + user.getUsername() + "].");
        }
    }
    TestUserInfo[] disAllowedUsers = new TestUserInfo[] { FastTestDataset.USER_MOHA_RA, FastTestDataset.USER_MOHA_RM, FastTestDataset.USER_MOHA_RC, FastTestDataset.USER_MOHA_AC, FastTestDataset.USER_CGOV_RC, FastTestDataset.USER_CGOV_AC };
    for (TestUserInfo user : disAllowedUsers) {
        try {
            FastTestDataset.runAsUser(user, (request, adapter) -> {
                testSetActionStatus(request, serializedCR);
                Assert.fail("Expected a permission exception to be thrown on user [" + user.getUsername() + "].");
            });
        } catch (SmartExceptionDTO e) {
            Assert.assertEquals(e.getType(), CGRPermissionException.CLASS);
        }
    }
}
Also used : TestUserInfo(net.geoprism.registry.test.TestUserInfo) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) Test(org.junit.Test)

Example 18 with SmartExceptionDTO

use of com.runwaysdk.business.SmartExceptionDTO in project geoprism-registry by terraframe.

the class GeoObjectRelationshipServiceTest method testGetHierarchiesPrivate.

@Test
public void testGetHierarchiesPrivate() {
    TestUserInfo[] allowedUsers = new TestUserInfo[] { FastTestDataset.USER_CGOV_RA, FastTestDataset.USER_CGOV_RM_PRIVATE };
    for (TestUserInfo user : allowedUsers) {
        TestDataSet.runAsUser(user, (request, adapter) -> {
            JsonArray ptn = adapter.getHierarchiesForGeoObjectOverTime(FastTestDataset.PROV_CENTRAL_PRIVATE.getCode(), FastTestDataset.PROVINCE_PRIVATE.getCode());
            Assert.assertEquals(1, ptn.size());
        });
    }
    TestUserInfo[] disallowedUsers = new TestUserInfo[] { FastTestDataset.USER_CGOV_RM, FastTestDataset.USER_CGOV_RC, FastTestDataset.USER_CGOV_AC, FastTestDataset.USER_MOHA_RA, FastTestDataset.USER_MOHA_RM, FastTestDataset.USER_MOHA_RC, FastTestDataset.USER_MOHA_AC };
    for (TestUserInfo user : disallowedUsers) {
        TestDataSet.runAsUser(user, (request, adapter) -> {
            try {
                adapter.getHierarchiesForGeoObjectOverTime(FastTestDataset.PROV_CENTRAL_PRIVATE.getCode(), FastTestDataset.PROVINCE_PRIVATE.getCode());
                Assert.fail("Expected a permission exception");
            } catch (SmartExceptionDTO ex) {
                Assert.assertEquals(ReadGeoObjectPermissionException.CLASS, ex.getType());
            }
        });
    }
}
Also used : JsonArray(com.google.gson.JsonArray) TestUserInfo(net.geoprism.registry.test.TestUserInfo) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) Test(org.junit.Test)

Example 19 with SmartExceptionDTO

use of com.runwaysdk.business.SmartExceptionDTO in project geoprism-registry by terraframe.

the class GeoObjectRelationshipServiceTest method testGetPrivateParentGeoObjects.

@Test
public void testGetPrivateParentGeoObjects() {
    final String childCode = FastTestDataset.PROV_CENTRAL_PRIVATE.getCode();
    final String childTypeCode = FastTestDataset.PROV_CENTRAL_PRIVATE.getGeoObjectType().getCode();
    final String[] parentTypes = new String[] { FastTestDataset.COUNTRY.getCode() };
    final List<TestGeoObjectInfo> expectedParents = new ArrayList<TestGeoObjectInfo>();
    expectedParents.add(FastTestDataset.CAMBODIA);
    TestUserInfo[] allowedUsers = new TestUserInfo[] { FastTestDataset.USER_CGOV_RA, FastTestDataset.USER_CGOV_RM_PRIVATE, FastTestDataset.USER_CGOV_RC_PRIVATE, FastTestDataset.USER_CGOV_AC_PRIVATE };
    for (TestUserInfo user : allowedUsers) {
        FastTestDataset.runAsUser(user, (request, adapter) -> {
            ParentTreeNode tn = adapter.getParentGeoObjects(childCode, childTypeCode, TestDataSet.DEFAULT_OVER_TIME_DATE, parentTypes, true);
            FastTestDataset.PROV_CENTRAL_PRIVATE.parentTreeNodeAssert(tn, expectedParents);
            Assert.assertEquals(tn.toJSON().toString(), ParentTreeNode.fromJSON(tn.toJSON().toString(), testData.adapter).toJSON().toString());
        });
    }
    TestUserInfo[] disallowedUsers = new TestUserInfo[] { FastTestDataset.USER_MOHA_RA, FastTestDataset.USER_MOHA_RM, FastTestDataset.USER_MOHA_RC, FastTestDataset.USER_MOHA_AC, FastTestDataset.USER_CGOV_RM, FastTestDataset.USER_CGOV_RC, FastTestDataset.USER_CGOV_AC };
    for (TestUserInfo user : disallowedUsers) {
        FastTestDataset.runAsUser(user, (request, adapter) -> {
            try {
                adapter.getParentGeoObjects(childCode, childTypeCode, TestDataSet.DEFAULT_OVER_TIME_DATE, parentTypes, true);
                Assert.fail("Expected a permissions error.");
            } catch (SmartExceptionDTO e) {
                Assert.assertEquals(ReadGeoObjectPermissionException.CLASS, e.getType());
            }
        });
    }
}
Also used : TestUserInfo(net.geoprism.registry.test.TestUserInfo) ArrayList(java.util.ArrayList) ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) TestGeoObjectInfo(net.geoprism.registry.test.TestGeoObjectInfo) Test(org.junit.Test)

Example 20 with SmartExceptionDTO

use of com.runwaysdk.business.SmartExceptionDTO in project geoprism-registry by terraframe.

the class GeoObjectServiceTest method testUpdatePrivateGeoObject.

@Test
public void testUpdatePrivateGeoObject() {
    // Allowed Users
    TestUserInfo[] allowedUsers = new TestUserInfo[] { FastTestDataset.USER_CGOV_RA, FastTestDataset.USER_CGOV_RM_PRIVATE };
    for (TestUserInfo user : allowedUsers) {
        TestGeoObjectInfo go = testData.newTestGeoObjectInfo("UpdateTest", FastTestDataset.PROVINCE_PRIVATE);
        go.apply();
        TestDataSet.runAsUser(user, (request, adapter) -> {
            updateGO(adapter, go, TestDataSet.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE);
        });
        go.delete();
    }
    // Disallowed Users
    TestUserInfo[] disallowedUsers = new TestUserInfo[] { FastTestDataset.USER_CGOV_RM, FastTestDataset.USER_CGOV_AC, FastTestDataset.USER_CGOV_RC, FastTestDataset.USER_MOHA_RA, FastTestDataset.USER_MOHA_RM, FastTestDataset.USER_MOHA_RC, FastTestDataset.USER_MOHA_AC };
    for (TestUserInfo user : disallowedUsers) {
        TestGeoObjectInfo go = testData.newTestGeoObjectInfo("UpdateTest", FastTestDataset.PROVINCE_PRIVATE);
        go.apply();
        TestDataSet.runAsUser(user, (request, adapter) -> {
            try {
                updateGO(adapter, go, TestDataSet.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE);
                Assert.fail();
            } catch (SmartExceptionDTO ex) {
            // expected
            }
        });
    }
}
Also used : TestUserInfo(net.geoprism.registry.test.TestUserInfo) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) TestGeoObjectInfo(net.geoprism.registry.test.TestGeoObjectInfo) Test(org.junit.Test)

Aggregations

SmartExceptionDTO (com.runwaysdk.business.SmartExceptionDTO)39 TestUserInfo (net.geoprism.registry.test.TestUserInfo)37 Test (org.junit.Test)35 JsonObject (com.google.gson.JsonObject)6 TestGeoObjectInfo (net.geoprism.registry.test.TestGeoObjectInfo)6 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)5 JsonArray (com.google.gson.JsonArray)3 ListTypeTest (net.geoprism.registry.service.ListTypeTest)3 CurationControllerWrapper (net.geoprism.registry.test.curation.CurationControllerWrapper)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 Point (com.vividsolutions.jts.geom.Point)2 ClassificationTypeTest (net.geoprism.registry.classification.ClassificationTypeTest)2 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)2 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)2 HierarchyType (org.commongeoregistry.adapter.metadata.HierarchyType)2 GeometryBuilder (org.geotools.geometry.jts.GeometryBuilder)2 ArrayList (java.util.ArrayList)1 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)1 GeoObjectTypeNotFoundException (org.commongeoregistry.adapter.GeoObjectTypeNotFoundException)1 GeoObjectOverTime (org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)1