Search in sources :

Example 1 with SmartExceptionDTO

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

the class CurationTest method testDetails.

@Test
public void testDetails() {
    // Allowed Users
    TestUserInfo[] allowedUsers = new TestUserInfo[] { FastTestDataset.USER_ADMIN, FastTestDataset.USER_CGOV_RA, FastTestDataset.USER_CGOV_RM };
    for (TestUserInfo user : allowedUsers) {
        FastTestDataset.runAsUser(user, (request, adapter) -> {
            CurationControllerWrapper controller = new CurationControllerWrapper(adapter, request);
            JsonObject details = controller.details(history.getOid(), false, 10, 1);
            Assert.assertTrue(details.has("page"));
            JsonObject page = details.get("page").getAsJsonObject();
            Assert.assertTrue(page.has("count"));
            Assert.assertTrue(page.has("pageNumber"));
            Assert.assertTrue(page.has("pageSize"));
            Assert.assertTrue(page.has("resultSet"));
            Assert.assertEquals(AllJobStatus.RUNNING.name(), details.get("status").getAsString());
            Assert.assertEquals(GeoRegistryUtil.formatDate(history.getCreateDate(), false), details.get("lastRun").getAsString());
            Assert.assertEquals(historyId, details.get("historyId").getAsString());
            Assert.assertEquals(job.getOid(), details.get("jobId").getAsString());
            Assert.assertFalse(details.has("exception"));
            Assert.assertEquals(TestDataSet.ADMIN_USER_NAME, details.get("lastRunBy").getAsString());
        });
    }
    // Disallowed Users
    TestUserInfo[] disallowedUsers = new TestUserInfo[] { FastTestDataset.USER_CGOV_RC, FastTestDataset.USER_CGOV_AC, FastTestDataset.USER_MOHA_RA, FastTestDataset.USER_MOHA_RM };
    for (TestUserInfo user : disallowedUsers) {
        FastTestDataset.runAsUser(user, (request, adapter) -> {
            CurationControllerWrapper controller = new CurationControllerWrapper(adapter, request);
            try {
                controller.details(history.getOid(), false, 10, 1);
                Assert.fail("Expected to get an exception.");
            } catch (SmartExceptionDTO e) {
                Assert.assertTrue(OrganizationRAException.CLASS.equals(e.getType()) || OrganizationRMException.CLASS.equals(e.getType()));
            }
        });
    }
}
Also used : TestUserInfo(net.geoprism.registry.test.TestUserInfo) CurationControllerWrapper(net.geoprism.registry.test.curation.CurationControllerWrapper) JsonObject(com.google.gson.JsonObject) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) ListTypeTest(net.geoprism.registry.service.ListTypeTest) Test(org.junit.Test)

Example 2 with SmartExceptionDTO

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

the class CurationTest method testPage.

@Test
public void testPage() {
    // Allowed Users
    TestUserInfo[] allowedUsers = new TestUserInfo[] { FastTestDataset.USER_ADMIN, FastTestDataset.USER_CGOV_RA, FastTestDataset.USER_CGOV_RM };
    for (TestUserInfo user : allowedUsers) {
        FastTestDataset.runAsUser(user, (request, adapter) -> {
            CurationControllerWrapper controller = new CurationControllerWrapper(adapter, request);
            JsonObject page = controller.page(history.getOid(), false, 10, 1);
            Assert.assertEquals(1, page.get("pageNumber").getAsInt());
            Assert.assertEquals(10, page.get("pageSize").getAsInt());
            Assert.assertEquals(1, page.get("count").getAsInt());
            Assert.assertTrue(page.has("resultSet"));
            JsonArray results = page.get("resultSet").getAsJsonArray();
            Assert.assertEquals(1, results.size());
            for (int i = 0; i < results.size(); ++i) {
                JsonObject problem = results.get(0).getAsJsonObject();
                Assert.assertEquals(historyId, problem.get("historyId").getAsString());
                Assert.assertEquals(CurationResolution.UNRESOLVED.name(), problem.get("resolution").getAsString());
                Assert.assertEquals(GeoObjectProblemType.NO_GEOMETRY.name(), problem.get("type").getAsString());
                Assert.assertEquals(curationProblemId, problem.get("id").getAsString());
                Assert.assertEquals(FastTestDataset.PROVINCE.getCode(), problem.get("typeCode").getAsString());
                Assert.assertEquals(FastTestDataset.PROV_CENTRAL.getCode(), problem.get("goCode").getAsString());
            }
        });
    }
    // Disallowed Users
    TestUserInfo[] disallowedUsers = new TestUserInfo[] { FastTestDataset.USER_CGOV_RC, FastTestDataset.USER_CGOV_AC, FastTestDataset.USER_MOHA_RA, FastTestDataset.USER_MOHA_RM };
    for (TestUserInfo user : disallowedUsers) {
        FastTestDataset.runAsUser(user, (request, adapter) -> {
            CurationControllerWrapper controller = new CurationControllerWrapper(adapter, request);
            try {
                controller.details(history.getOid(), false, 10, 1);
                Assert.fail("Expected to get an exception.");
            } catch (SmartExceptionDTO e) {
                Assert.assertTrue(OrganizationRAException.CLASS.equals(e.getType()) || OrganizationRMException.CLASS.equals(e.getType()));
            }
        });
    }
}
Also used : JsonArray(com.google.gson.JsonArray) TestUserInfo(net.geoprism.registry.test.TestUserInfo) CurationControllerWrapper(net.geoprism.registry.test.curation.CurationControllerWrapper) JsonObject(com.google.gson.JsonObject) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) ListTypeTest(net.geoprism.registry.service.ListTypeTest) Test(org.junit.Test)

Example 3 with SmartExceptionDTO

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

the class GeoObjectTypeRelationshipServiceTest method testAddChild.

@Test
public void testAddChild() {
    TEST_CHILD.apply();
    USER_CHILD_GOT_RM.apply();
    USER_CHILD_GOT_RC.apply();
    USER_CHILD_GOT_AC.apply();
    // Allowed Users (with ROOT as parent)
    for (TestUserInfo user : new TestUserInfo[] { FastTestDataset.USER_CGOV_RA, USER_CHILD_GOT_RM }) {
        TestDataSet.runAsUser(user, (request, adapter) -> {
            addChild(adapter, null, TEST_CHILD);
            TEST_HT.delete();
            TEST_HT.apply();
        });
    }
    // Disallowed Users (with ROOT as parent)
    for (TestUserInfo user : new TestUserInfo[] { FastTestDataset.USER_CGOV_RM, USER_CHILD_GOT_RC, USER_CHILD_GOT_AC, FastTestDataset.USER_MOHA_RA, FastTestDataset.USER_MOHA_RM, FastTestDataset.USER_MOHA_RC, FastTestDataset.USER_MOHA_AC }) {
        TestDataSet.runAsUser(user, (request, adapter) -> {
            try {
                addChild(adapter, null, TEST_CHILD);
                Assert.fail("Expected an error");
            } catch (SmartExceptionDTO ex) {
                Assert.assertEquals(HierarchyRelationshipPermissionException.CLASS, ex.getType());
            }
        });
    }
}
Also used : TestUserInfo(net.geoprism.registry.test.TestUserInfo) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) Test(org.junit.Test)

Example 4 with SmartExceptionDTO

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

the class HierarchyServiceTest method testUpdateHierarchyTypeAsBadRole.

@Test
public void testUpdateHierarchyTypeAsBadRole() {
    HierarchyType reportingDivision = FastTestDataset.HIER_ADMIN.toDTO();
    reportingDivision.setLabel(new LocalizedValue("Reporting Division 2"));
    reportingDivision.setDescription(new LocalizedValue("The rporting division hieracy 2"));
    final String updateJSON = reportingDivision.toJSON().toString();
    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().updateHierarchyType(request.getSessionId(), updateJSON);
            });
            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 5 with SmartExceptionDTO

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

the class CurationTest method testCurate.

@Test
public void testCurate() throws Throwable {
    Object[] setup = setUpTestCurate();
    final TestGeoObjectInfo noGeomGo = (TestGeoObjectInfo) setup[0];
    final String listTypeVersionId = (String) setup[1];
    // Allowed Users
    TestUserInfo[] allowedUsers = new TestUserInfo[] { FastTestDataset.USER_ADMIN, FastTestDataset.USER_CGOV_RA, FastTestDataset.USER_CGOV_RM };
    for (TestUserInfo user : allowedUsers) {
        FastTestDataset.runAsUser(user, (request, adapter) -> {
            final CurationControllerWrapper controller = new CurationControllerWrapper(adapter, request);
            JsonObject joHistory = controller.curate(listTypeVersionId);
            try {
                waitUntilSuccess(joHistory);
            } catch (Throwable e) {
                throw new RuntimeException(e);
            }
            JsonObject page = controller.page(joHistory.get("historyId").getAsString(), false, 10, 1);
            JsonArray results = page.get("resultSet").getAsJsonArray();
            Assert.assertEquals(1, results.size());
            for (int i = 0; i < results.size(); ++i) {
                JsonObject problem = results.get(i).getAsJsonObject();
                Assert.assertEquals(joHistory.get("historyId").getAsString(), problem.get("historyId").getAsString());
                Assert.assertEquals(CurationResolution.UNRESOLVED.name(), problem.get("resolution").getAsString());
                Assert.assertEquals(GeoObjectProblemType.NO_GEOMETRY.name(), problem.get("type").getAsString());
                Assert.assertTrue(problem.get("id").getAsString() != null && problem.get("id").getAsString() != "");
                Assert.assertEquals(FastTestDataset.PROVINCE.getCode(), problem.get("typeCode").getAsString());
                Assert.assertEquals(noGeomGo.getCode(), problem.get("goCode").getAsString());
            }
        });
    }
    // Disallowed Users
    TestUserInfo[] disallowedUsers = new TestUserInfo[] { FastTestDataset.USER_CGOV_RC, FastTestDataset.USER_CGOV_AC, FastTestDataset.USER_MOHA_RA, FastTestDataset.USER_MOHA_RM };
    for (TestUserInfo user : disallowedUsers) {
        FastTestDataset.runAsUser(user, (request, adapter) -> {
            final CurationControllerWrapper controller = new CurationControllerWrapper(adapter, request);
            try {
                controller.curate(listTypeVersionId);
                Assert.fail("Expected to get an exception.");
            } catch (SmartExceptionDTO e) {
                Assert.assertTrue(OrganizationRAException.CLASS.equals(e.getType()) || OrganizationRMException.CLASS.equals(e.getType()));
            }
        });
    }
}
Also used : CurationControllerWrapper(net.geoprism.registry.test.curation.CurationControllerWrapper) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) TestUserInfo(net.geoprism.registry.test.TestUserInfo) JsonObject(com.google.gson.JsonObject) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) TestGeoObjectInfo(net.geoprism.registry.test.TestGeoObjectInfo) ListTypeTest(net.geoprism.registry.service.ListTypeTest) 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