Search in sources :

Example 1 with GeoObjectTypeNotFoundException

use of org.commongeoregistry.adapter.GeoObjectTypeNotFoundException in project geoprism-registry by terraframe.

the class GeoObjectServiceTest method testCreatePrivateGeoObject.

@Test
public void testCreatePrivateGeoObject() {
    // Allowed Users
    TestUserInfo[] allowedUsers = new TestUserInfo[] { FastTestDataset.USER_CGOV_RA, FastTestDataset.USER_CGOV_RM_PRIVATE };
    for (TestUserInfo user : allowedUsers) {
        TestDataSet.runAsUser(user, (request, adapter) -> {
            TestDataSet.populateAdapterIds(user, adapter);
            GeoObject returned = adapter.createGeoObject(TEST_GO_PRIVATE.newGeoObject(adapter).toJSON().toString(), TestDataSet.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE);
            TEST_GO_PRIVATE.assertEquals(returned);
            Assert.assertEquals(true, returned.getExists());
            TEST_GO_PRIVATE.assertApplied();
            TEST_GO_PRIVATE.delete();
        });
    }
    // Disallowed Users
    TestUserInfo[] disallowedUsers = new TestUserInfo[] { 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) -> {
            if (TestDataSet.populateAdapterIds(user, adapter)) {
                try {
                    adapter.newGeoObjectInstance(FastTestDataset.PROVINCE_PRIVATE.getCode());
                    Assert.fail("Expected an error: " + user.getUsername());
                } catch (GeoObjectTypeNotFoundException ex) {
                // Expected
                }
            }
            try {
                adapter.createGeoObject(TEST_GO_PRIVATE.newGeoObject(ServiceFactory.getAdapter()).toJSON().toString(), TestDataSet.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE);
                Assert.fail();
            } catch (SmartExceptionDTO ex) {
                Assert.assertEquals(CreateGeoObjectPermissionException.CLASS, ex.getType());
            }
        });
    }
}
Also used : GeoObjectTypeNotFoundException(org.commongeoregistry.adapter.GeoObjectTypeNotFoundException) TestUserInfo(net.geoprism.registry.test.TestUserInfo) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) SmartExceptionDTO(com.runwaysdk.business.SmartExceptionDTO) TestGeoObjectInfo(net.geoprism.registry.test.TestGeoObjectInfo) Test(org.junit.Test)

Aggregations

SmartExceptionDTO (com.runwaysdk.business.SmartExceptionDTO)1 TestGeoObjectInfo (net.geoprism.registry.test.TestGeoObjectInfo)1 TestUserInfo (net.geoprism.registry.test.TestUserInfo)1 GeoObjectTypeNotFoundException (org.commongeoregistry.adapter.GeoObjectTypeNotFoundException)1 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)1 Test (org.junit.Test)1