Search in sources :

Example 21 with SmartExceptionDTO

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

the class GeoObjectServiceTest method testGetPrivateGeoObject.

@Test
public void testGetPrivateGeoObject() {
    // Test allowed users on a private GeoObjectType
    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) -> {
            GeoObject geoObj = adapter.getGeoObject(FastTestDataset.PROV_CENTRAL_PRIVATE.getRegistryId(), FastTestDataset.PROV_CENTRAL_PRIVATE.getGeoObjectType().getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
            FastTestDataset.PROV_CENTRAL_PRIVATE.assertEquals(geoObj);
            Assert.assertEquals(true, geoObj.getExists());
        });
    }
    // Disallowed Users
    TestUserInfo[] disllowedUsers = 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 : disllowedUsers) {
        try {
            FastTestDataset.runAsUser(user, (request, adapter) -> {
                adapter.getGeoObject(FastTestDataset.PROV_CENTRAL_PRIVATE.getRegistryId(), FastTestDataset.PROV_CENTRAL_PRIVATE.getGeoObjectType().getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
                Assert.fail();
            });
        } catch (SmartExceptionDTO e) {
        // Expected
        }
    }
}
Also used : TestUserInfo(net.geoprism.registry.test.TestUserInfo) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) Test(org.junit.Test)

Example 22 with SmartExceptionDTO

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

the class GeoObjectServiceTest method testGetPrivateGeoObjectByCode.

@Test
public void testGetPrivateGeoObjectByCode() {
    // Allowed Users
    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) -> {
            GeoObject geoObj = adapter.getGeoObjectByCode(FastTestDataset.PROV_CENTRAL_PRIVATE.getCode(), FastTestDataset.PROV_CENTRAL_PRIVATE.getGeoObjectType().getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
            Assert.assertEquals(geoObj.toJSON().toString(), GeoObject.fromJSON(adapter, geoObj.toJSON().toString()).toJSON().toString());
            Assert.assertEquals(true, geoObj.getExists());
        });
    }
    // Disallowed Users
    TestUserInfo[] disllowedUsers = 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 : disllowedUsers) {
        try {
            FastTestDataset.runAsUser(user, (request, adapter) -> {
                adapter.getGeoObjectByCode(FastTestDataset.PROV_CENTRAL_PRIVATE.getCode(), FastTestDataset.PROV_CENTRAL_PRIVATE.getGeoObjectType().getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
                Assert.fail();
            });
        } catch (SmartExceptionDTO e) {
        // This is expected
        }
    }
}
Also used : TestUserInfo(net.geoprism.registry.test.TestUserInfo) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) Test(org.junit.Test)

Example 23 with SmartExceptionDTO

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

the class ListTypeTest method testRemoveFromBadRole.

@Test
public void testRemoveFromBadRole() {
    JsonObject listJson = getJson(USATestData.ORG_NPS.getServerObject(), USATestData.HIER_ADMIN, USATestData.STATE, USATestData.COUNTRY);
    ListTypeService service = new ListTypeService();
    JsonObject result = service.apply(testData.clientRequest.getSessionId(), listJson);
    String oid = result.get(ComponentInfo.OID).getAsString();
    this.waitUntilPublished(oid);
    try {
        TestUserInfo[] users = new TestUserInfo[] { USATestData.USER_PPP_RA };
        for (TestUserInfo user : users) {
            USATestData.runAsUser(user, (request, adapter) -> {
                try {
                    service.remove(request.getSessionId(), oid);
                    Assert.fail("Expected an exception to be thrown.");
                } catch (SmartExceptionDTO e) {
                // This is expected
                }
            });
        }
    } finally {
        service.remove(testData.clientRequest.getSessionId(), oid);
    }
}
Also used : TestUserInfo(net.geoprism.registry.test.TestUserInfo) JsonObject(com.google.gson.JsonObject) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) ClassificationTypeTest(net.geoprism.registry.classification.ClassificationTypeTest) Test(org.junit.Test)

Example 24 with SmartExceptionDTO

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

the class HierarchyServiceTest method testDeleteHierarchyTypeAsBadRole.

@Test
public void testDeleteHierarchyTypeAsBadRole() {
    String organizationCode = FastTestDataset.ORG_CGOV.getCode();
    HierarchyType reportingDivision = MetadataFactory.newHierarchyType(TEST_HT.getCode(), new LocalizedValue("Reporting Division"), new LocalizedValue("The rporting division hieracy..."), organizationCode, testData.adapter);
    String gtJSON = reportingDivision.toJSON().toString();
    ServiceFactory.getHierarchyService().createHierarchyType(testData.clientSession.getSessionId(), gtJSON);
    TestUserInfo[] users = new TestUserInfo[] { FastTestDataset.USER_MOHA_RA, FastTestDataset.USER_CGOV_RC, FastTestDataset.USER_CGOV_AC, FastTestDataset.USER_CGOV_RM };
    for (TestUserInfo user : users) {
        try {
            FastTestDataset.runAsUser(user, (request, adapter) -> {
                ServiceFactory.getHierarchyService().deleteHierarchyType(request.getSessionId(), TEST_HT.getCode());
            });
            Assert.fail("Able to update a geo object type as a user with bad roles");
        } catch (SmartExceptionDTO e) {
        // This is expected
        }
    }
}
Also used : TestUserInfo(net.geoprism.registry.test.TestUserInfo) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) Test(org.junit.Test)

Example 25 with SmartExceptionDTO

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

the class ChangeRequestDocumentActionServiceTest method testListDocuments.

// @Test
public void testListDocuments() {
    uploadDocumentsAsAdmin();
    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) -> {
                testListDocumentsAsUser(request);
            });
        } 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) -> {
                testListDocumentsAsUser(request);
                Assert.fail("Expected a permission exception.");
            });
        } catch (SmartExceptionDTO e) {
            Assert.assertEquals(CGRPermissionException.CLASS, e.getType());
        // Expected
        }
    }
}
Also used : TestUserInfo(net.geoprism.registry.test.TestUserInfo) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO)

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