Search in sources :

Example 1 with TestGeoObjectInfo

use of net.geoprism.registry.test.TestGeoObjectInfo in project geoprism-registry by terraframe.

the class CurationTest method setUpTestCurate.

@Request
private Object[] setUpTestCurate() throws Throwable {
    TestGeoObjectInfo noGeomGo = testData.newTestGeoObjectInfo("curationJobTest-NoGeom", FastTestDataset.PROVINCE);
    noGeomGo.setWkt(null);
    noGeomGo.apply();
    version.publishNoAuth();
    return new Object[] { noGeomGo, version.getOid() };
}
Also used : JsonObject(com.google.gson.JsonObject) TestGeoObjectInfo(net.geoprism.registry.test.TestGeoObjectInfo) Request(com.runwaysdk.session.Request)

Example 2 with TestGeoObjectInfo

use of net.geoprism.registry.test.TestGeoObjectInfo 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)

Example 3 with TestGeoObjectInfo

use of net.geoprism.registry.test.TestGeoObjectInfo in project geoprism-registry by terraframe.

the class GeoObjectRelationshipServiceTest method testGetChildGeoObjects.

@Test
public void testGetChildGeoObjects() {
    final String parentCode = FastTestDataset.CAMBODIA.getCode();
    final String parentTypeCode = FastTestDataset.CAMBODIA.getGeoObjectType().getCode();
    final String[] childrenTypes = new String[] { FastTestDataset.PROVINCE.getCode() };
    final List<TestGeoObjectInfo> expectedChildren = new ArrayList<TestGeoObjectInfo>();
    expectedChildren.add(FastTestDataset.PROV_CENTRAL);
    expectedChildren.add(FastTestDataset.PROV_CENTRAL);
    expectedChildren.add(FastTestDataset.PROV_WESTERN);
    // Recursive
    ChildTreeNode tn = testData.adapter.getChildGeoObjects(parentCode, parentTypeCode, TestDataSet.DEFAULT_OVER_TIME_DATE, childrenTypes, true);
    FastTestDataset.CAMBODIA.childTreeNodeAssert(tn, expectedChildren);
    Assert.assertEquals(tn.toJSON().toString(), ChildTreeNode.fromJSON(tn.toJSON().toString(), testData.adapter).toJSON().toString());
    // Not recursive
    ChildTreeNode tn2 = testData.adapter.getChildGeoObjects(parentCode, parentTypeCode, TestDataSet.DEFAULT_OVER_TIME_DATE, childrenTypes, false);
    FastTestDataset.CAMBODIA.childTreeNodeAssert(tn2, expectedChildren);
    Assert.assertEquals(tn2.toJSON().toString(), ChildTreeNode.fromJSON(tn2.toJSON().toString(), testData.adapter).toJSON().toString());
    // Null date
    ChildTreeNode tn3 = testData.adapter.getChildGeoObjects(parentCode, parentTypeCode, null, childrenTypes, false);
    FastTestDataset.CAMBODIA.childTreeNodeAssert(tn3, expectedChildren);
    Assert.assertEquals(tn3.toJSON().toString(), ChildTreeNode.fromJSON(tn3.toJSON().toString(), testData.adapter).toJSON().toString());
}
Also used : ArrayList(java.util.ArrayList) ChildTreeNode(org.commongeoregistry.adapter.dataaccess.ChildTreeNode) TestGeoObjectInfo(net.geoprism.registry.test.TestGeoObjectInfo) Test(org.junit.Test)

Example 4 with TestGeoObjectInfo

use of net.geoprism.registry.test.TestGeoObjectInfo 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 5 with TestGeoObjectInfo

use of net.geoprism.registry.test.TestGeoObjectInfo 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

TestGeoObjectInfo (net.geoprism.registry.test.TestGeoObjectInfo)15 Test (org.junit.Test)13 TestUserInfo (net.geoprism.registry.test.TestUserInfo)7 SmartExceptionDTO (com.runwaysdk.business.SmartExceptionDTO)6 ArrayList (java.util.ArrayList)4 ChildTreeNode (org.commongeoregistry.adapter.dataaccess.ChildTreeNode)4 ParentTreeNode (org.commongeoregistry.adapter.dataaccess.ParentTreeNode)4 JsonObject (com.google.gson.JsonObject)2 Request (com.runwaysdk.session.Request)2 JsonArray (com.google.gson.JsonArray)1 Point (com.vividsolutions.jts.geom.Point)1 UpdateGeoObjectAction (net.geoprism.registry.action.geoobject.UpdateGeoObjectAction)1 ListTypeTest (net.geoprism.registry.service.ListTypeTest)1 CurationControllerWrapper (net.geoprism.registry.test.curation.CurationControllerWrapper)1 GeoObjectTypeNotFoundException (org.commongeoregistry.adapter.GeoObjectTypeNotFoundException)1 UpdateGeoObjectActionDTO (org.commongeoregistry.adapter.action.geoobject.UpdateGeoObjectActionDTO)1 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)1 GeoObjectOverTime (org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)1