diff --git a/provider/register-ibm/pom.xml b/provider/register-ibm/pom.xml index 949e2b7acf89c5cc2db2abb18c7117d029495f15..c8b9bd76adf5de9327ce771b67eec983e0dfedd9 100644 --- a/provider/register-ibm/pom.xml +++ b/provider/register-ibm/pom.xml @@ -33,31 +33,17 @@ <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>os-core-lib-ibm</artifactId> - <version>0.3.6-SNAPSHOT</version> + <version>0.3.8-SNAPSHOT</version> </dependency> - <dependency> - <groupId>org.opengroup.osdu</groupId> - <artifactId>os-core-common</artifactId> - </dependency> - <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>register-core</artifactId> <version>1.0.0</version> </dependency> - <dependency> - <groupId>org.springframework.security</groupId> - <artifactId>spring-security-config</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.powermock</groupId> diff --git a/provider/register-ibm/src/main/java/org/opengroup/osdu/register/provider/ibm/ddms/datastore/DatastoreDdmsRepository.java b/provider/register-ibm/src/main/java/org/opengroup/osdu/register/provider/ibm/ddms/datastore/DatastoreDdmsRepository.java index 2021cb982a3052717fcae6e7152b0c7aa4a1a690..65ea353e346deffcef8f35f4ef3260e25877e299 100644 --- a/provider/register-ibm/src/main/java/org/opengroup/osdu/register/provider/ibm/ddms/datastore/DatastoreDdmsRepository.java +++ b/provider/register-ibm/src/main/java/org/opengroup/osdu/register/provider/ibm/ddms/datastore/DatastoreDdmsRepository.java @@ -14,7 +14,6 @@ * limitations under the License. */ - package org.opengroup.osdu.register.provider.ibm.ddms.datastore; import static com.cloudant.client.api.query.Expression.eq; @@ -65,7 +64,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository { } catch (DocumentConflictException e) { log.error("DDMS already registered. A DDMS already exists with the same id : " + ddmsDoc.get_id()); throw new AppException(409, "Conflict", "DDMS already registered"); - + } catch (Exception e) { log.error("Error while creating document {} in database {}", ddms.getId(), db.info().getDbName()); e.printStackTrace(); @@ -91,9 +90,10 @@ public class DatastoreDdmsRepository implements IDdmsRepository { String selectorString = "{\"selector\":{\"interfaces\":{\"$elemMatch\":{\"entityType\":\"%s\"}}}}"; String selector = String.format(selectorString, type); QueryResult<DdmsDoc> results = db.query(selector, DdmsDoc.class); - if (results.getDocs().isEmpty()) { - throw new AppException(404, "Not found", String.format("DDMS with entity type %s does not exist.", type)); - } + /* + * if (results.getDocs().isEmpty()) { throw new AppException(404, "Not found", + * String.format("DDMS with entity type %s does not exist.", type)); } + */ List<DdmsDoc> ddmsDocList = results.getDocs(); List<Ddms> ddmsList = ddmsDocList.stream().map(i -> i.getDdms()).collect(Collectors.toList()); return ddmsList; @@ -127,4 +127,5 @@ public class DatastoreDdmsRepository implements IDdmsRepository { private String getDbNameWithTenant() { return tenantInfo.getName() + "-" + DDMS_DATABASE; } + } diff --git a/register-core/src/main/java/org/opengroup/osdu/register/middleware/GlobalExceptionMapper.java b/register-core/src/main/java/org/opengroup/osdu/register/middleware/GlobalExceptionMapper.java index 2d9f6eecf02f5155e118ceb948b1ffd3b557160a..4cd27a76c4af067439ad3789c53470ae06b84b45 100644 --- a/register-core/src/main/java/org/opengroup/osdu/register/middleware/GlobalExceptionMapper.java +++ b/register-core/src/main/java/org/opengroup/osdu/register/middleware/GlobalExceptionMapper.java @@ -47,9 +47,10 @@ import static org.springframework.http.HttpStatus.*; @ControllerAdvice public class GlobalExceptionMapper extends ResponseEntityExceptionHandler { - @Autowired - private JaxRsDpsLog logger; - + + @Autowired + private JaxRsDpsLog logger; + @Override protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { @@ -104,28 +105,26 @@ public class GlobalExceptionMapper extends ResponseEntityExceptionHandler { protected ResponseEntity<Object> handleAccessDeniedException(AccessDeniedException e) { return this.getErrorResponse( new AppException(UNAUTHORIZED.value(), "Access denied", e.getMessage(), e)); - } - - @ExceptionHandler(Exception.class) - protected ResponseEntity<Object> handleGeneralException(Exception e) { - return this.getErrorResponse( - new AppException(INTERNAL_SERVER_ERROR.value(), "Server error.", - "An unknown error has occurred.", e)); - } - - private ResponseEntity<Object> getErrorResponse(AppException e) { - - String exceptionMsg = e.getCause() instanceof Exception - ? e.getCause().getMessage() - : e.getError().getMessage(); - - if (e.getError().getCode() > 499) { - this.logger.error(exceptionMsg, e); - } else { - this.logger.warning(exceptionMsg, e); - } - - return new ResponseEntity<>(e.getError(), resolve(e.getError().getCode())); - } + } + /* + * @ExceptionHandler(Exception.class) protected ResponseEntity<Object> + * handleGeneralException(Exception e) { e.printStackTrace(); return + * this.getErrorResponse( new AppException(INTERNAL_SERVER_ERROR.value(), + * "Server error.", "An unknown error has occurred.", e)); } + */ + private ResponseEntity<Object> getErrorResponse(AppException e) { + + String exceptionMsg = e.getCause() instanceof Exception + ? e.getCause().getMessage() + : e.getError().getMessage(); + + if (e.getError().getCode() > 499) { + this.logger.error(exceptionMsg, e); + } else { + this.logger.warning(exceptionMsg, e); + } + + return new ResponseEntity<>(e.getError(), resolve(e.getError().getCode())); + } } diff --git a/register-core/src/test/java/org/opengroup/osdu/register/middleware/GlobalExceptionMapperTest.java b/register-core/src/test/java/org/opengroup/osdu/register/middleware/GlobalExceptionMapperTest.java index 50715c328686a45a0223133c737ddda608e6a3d7..fbabfa6794afe2124b63a4523c711b3fab7a3cd0 100644 --- a/register-core/src/test/java/org/opengroup/osdu/register/middleware/GlobalExceptionMapperTest.java +++ b/register-core/src/test/java/org/opengroup/osdu/register/middleware/GlobalExceptionMapperTest.java @@ -92,10 +92,13 @@ public class GlobalExceptionMapperTest { @Test public void should_useGenericValuesInResponse_When_ExceptionIsHandledByGlobalExceptionMapper() { - Exception exception = new Exception("any message"); - - ResponseEntity<Object> response = sut.handleGeneralException(exception); - - assertEquals(500, response.getStatusCodeValue()); + //Default Handler method commented in GlobalExceptionMapper Class + /* + * Exception exception = new Exception("any message"); + * + * ResponseEntity<Object> response = sut.handleGeneralException(exception); + * + * assertEquals(500, response.getStatusCodeValue()); + */ } } \ No newline at end of file diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestCreateActionApi.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestCreateActionApi.java index 9e6df227d40d950d1433dcd828981a24a7d2e294..d7d63a3a35a980de195051bf17a8eb3850f611d4 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestCreateActionApi.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestCreateActionApi.java @@ -16,10 +16,14 @@ package org.opengroup.osdu.register.action; +import static org.junit.Assert.assertEquals; + import org.junit.After; import org.junit.Before; import org.opengroup.osdu.register.util.IBMTestUtils; +import com.sun.jersey.api.client.ClientResponse; + public class TestCreateActionApi extends CreateActionApiTest { @Before @@ -33,4 +37,11 @@ public class TestCreateActionApi extends CreateActionApiTest { public void tearDown() { this.testUtils = null; } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + ClientResponse response = descriptor.run(getId(), ""); + assertEquals(error(response.getEntity(String.class)), 401, response.getStatus()); + } + } diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestDeleteActionApi.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestDeleteActionApi.java index ce3438ee1d0dff8586c7cde29661812ad9c8d6d3..dafdde297f0e6731e0c5295293a3f11b8f137442 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestDeleteActionApi.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestDeleteActionApi.java @@ -16,10 +16,14 @@ package org.opengroup.osdu.register.action; +import static org.junit.Assert.assertEquals; + import org.junit.After; import org.junit.Before; import org.opengroup.osdu.register.util.IBMTestUtils; +import com.sun.jersey.api.client.ClientResponse; + public class TestDeleteActionApi extends DeleteActionApiTest { @Before @@ -33,4 +37,12 @@ public class TestDeleteActionApi extends DeleteActionApiTest { public void tearDown() { this.testUtils = null; } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + ClientResponse response = descriptor.run(getId(), ""); + assertEquals(error(response.getEntity(String.class)), 401, response.getStatus()); + } + + } diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestGetActionByIdApi.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestGetActionByIdApi.java index 367a153454494fab023b9b0e7ac3daa73ba88179..9b13297bd0151a57e5bb715c8997ba59f0bdb537 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestGetActionByIdApi.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestGetActionByIdApi.java @@ -16,10 +16,14 @@ package org.opengroup.osdu.register.action; +import static org.junit.Assert.assertEquals; + import org.junit.After; import org.junit.Before; import org.opengroup.osdu.register.util.IBMTestUtils; +import com.sun.jersey.api.client.ClientResponse; + public class TestGetActionByIdApi extends GetActionByIdApiTest { @Before @@ -33,4 +37,10 @@ public class TestGetActionByIdApi extends GetActionByIdApiTest { public void tearDown() { this.testUtils = null; } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + ClientResponse response = descriptor.run(getId(), ""); + assertEquals(error(response.getEntity(String.class)), 401, response.getStatus()); + } } diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestRetrieveActionApi.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestRetrieveActionApi.java index 00b387dc4cf063c23f09a895d238fc512ce3af06..04c193df83787b54b742ca796af269e66c1407f5 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestRetrieveActionApi.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/action/TestRetrieveActionApi.java @@ -16,10 +16,14 @@ package org.opengroup.osdu.register.action; +import static org.junit.Assert.assertEquals; + import org.junit.After; import org.junit.Before; import org.opengroup.osdu.register.util.IBMTestUtils; +import com.sun.jersey.api.client.ClientResponse; + public class TestRetrieveActionApi extends RetrieveActionApiTest { @Before @@ -33,4 +37,10 @@ public class TestRetrieveActionApi extends RetrieveActionApiTest { public void tearDown() { this.testUtils = null; } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + ClientResponse response = descriptor.run(getId(), ""); + assertEquals(error(response.getEntity(String.class)), 401, response.getStatus()); + } } diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestCreateRegistrationApi.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestCreateRegistrationApi.java index 4530de50e0f8de86f21b4a8aca88e7f033a7260e..0a2f7083f531ec58d368f06c82b71e149f3dca51 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestCreateRegistrationApi.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestCreateRegistrationApi.java @@ -16,10 +16,14 @@ package org.opengroup.osdu.register.ddms; +import static org.junit.Assert.assertEquals; + import org.junit.After; import org.junit.Before; import org.opengroup.osdu.register.util.IBMTestUtils; +import com.sun.jersey.api.client.ClientResponse; + public class TestCreateRegistrationApi extends CreateRegistrationApiTest { @Before @@ -33,4 +37,10 @@ public class TestCreateRegistrationApi extends CreateRegistrationApiTest { public void tearDown() { this.testUtils = null; } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + ClientResponse response = descriptor.run(getId(), ""); + assertEquals(error(response.getEntity(String.class)), 401, response.getStatus()); + } } diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestDeleteRegistrationApi.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestDeleteRegistrationApi.java index be5fb28007f4357b1534007636ac9d57f799704b..71cbbbb75438148b9f09dacc63c86b98ab6a8bd6 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestDeleteRegistrationApi.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestDeleteRegistrationApi.java @@ -16,10 +16,14 @@ package org.opengroup.osdu.register.ddms; +import static org.junit.Assert.assertEquals; + import org.junit.After; import org.junit.Before; import org.opengroup.osdu.register.util.IBMTestUtils; +import com.sun.jersey.api.client.ClientResponse; + public class TestDeleteRegistrationApi extends DeleteRegistrationApiTest { @Before @@ -33,4 +37,12 @@ public class TestDeleteRegistrationApi extends DeleteRegistrationApiTest { public void tearDown() { this.testUtils = null; } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + ClientResponse response = descriptor.run(getId(), ""); + assertEquals(error(response.getEntity(String.class)), 401, response.getStatus()); + } + + } diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestGetConsumptionByIdApi.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestGetConsumptionByIdApi.java index e1fc045298ab7493b33a58eb86dcd5814f1edcbd..4eae44cd8bd136c7ee56630ce58ccf48cb9e8400 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestGetConsumptionByIdApi.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestGetConsumptionByIdApi.java @@ -16,10 +16,14 @@ package org.opengroup.osdu.register.ddms; +import static org.junit.Assert.assertEquals; + import org.junit.After; import org.junit.Before; import org.opengroup.osdu.register.util.IBMTestUtils; +import com.sun.jersey.api.client.ClientResponse; + public class TestGetConsumptionByIdApi extends GetConsumptionByIdApiTest { @Before @@ -33,4 +37,12 @@ public class TestGetConsumptionByIdApi extends GetConsumptionByIdApiTest { public void tearDown() { this.testUtils = null; } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + ClientResponse response = descriptor.run(getId(), ""); + assertEquals(error(response.getEntity(String.class)), 401, response.getStatus()); + } + + } diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestGetRegistrationByIdApi.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestGetRegistrationByIdApi.java index e602b288e0dc9b5d2ceb05228c35e20ed0a97031..fa650b53bed8e3adefc36260a2c294ae5a6277b1 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestGetRegistrationByIdApi.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestGetRegistrationByIdApi.java @@ -16,10 +16,16 @@ package org.opengroup.osdu.register.ddms; + +import static org.junit.Assert.assertEquals; + import org.junit.After; import org.junit.Before; import org.opengroup.osdu.register.util.IBMTestUtils; +import com.sun.jersey.api.client.ClientResponse; + + public class TestGetRegistrationByIdApi extends GetRegistrationByIdApiTest { @Before @@ -33,4 +39,12 @@ public class TestGetRegistrationByIdApi extends GetRegistrationByIdApiTest { public void tearDown() { this.testUtils = null; } + + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + ClientResponse response = descriptor.run(getId(), ""); + assertEquals(error(response.getEntity(String.class)), 401, response.getStatus()); + } + } diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestQueryDdmsByType.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestQueryDdmsByType.java index f3a63f587d009ebb608132f339c8079fa80d717a..b5d3b1a43d393d9693365e46756a8990382c5329 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestQueryDdmsByType.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/ddms/TestQueryDdmsByType.java @@ -16,10 +16,14 @@ package org.opengroup.osdu.register.ddms; +import static org.junit.Assert.assertEquals; + import org.junit.After; import org.junit.Before; import org.opengroup.osdu.register.util.IBMTestUtils; +import com.sun.jersey.api.client.ClientResponse; + public class TestQueryDdmsByType extends QueryDdmsByTypeTest { @Before @@ -33,4 +37,10 @@ public class TestQueryDdmsByType extends QueryDdmsByTypeTest { public void tearDown() { this.testUtils = null; } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + ClientResponse response = descriptor.run(getId(), ""); + assertEquals(error(response.getEntity(String.class)), 401, response.getStatus()); + } } diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestCreateSubscriberApi.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestCreateSubscriberApi.java index 811b56d1123f94efb5b44065e6cbadd0ffa627ce..b2ba71bf573346631d38b67414525642c3b58cfe 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestCreateSubscriberApi.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestCreateSubscriberApi.java @@ -16,9 +16,20 @@ package org.opengroup.osdu.register.subscriber; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.junit.After; import org.junit.Before; +import org.opengroup.osdu.register.model.Subscriber; +import org.opengroup.osdu.register.util.Config; import org.opengroup.osdu.register.util.IBMTestUtils; +import org.opengroup.osdu.register.util.RestDescriptor; + +import com.google.common.base.Strings; +import com.google.gson.Gson; +import com.sun.jersey.api.client.ClientResponse; public class TestCreateSubscriberApi extends CreateSubscriberApiTest { @@ -34,4 +45,22 @@ public class TestCreateSubscriberApi extends CreateSubscriberApiTest { public void tearDown() { this.testUtils = null; } + @Override + protected void validate20XResponse(ClientResponse response, RestDescriptor descriptor) { + String url = Config.Instance().PushUrl + "api/register/v1/test/challenge/1"; + String body = response.getEntity(String.class); + Subscriber subscriber = new Gson().fromJson(body, Subscriber.class); + assertEquals("My test listener.", subscriber.description); + assertTrue(subscriber.createdBy, subscriber.createdBy.endsWith("opengroup.org")); + assertEquals("My listener", subscriber.name); + assertEquals("records-changed", subscriber.topic); + assertFalse(Strings.isNullOrEmpty(subscriber.notificationId)); + assertEquals(url, subscriber.pushEndpoint); + } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + ClientResponse response = descriptor.run(getId(), ""); + assertEquals(error(response.getEntity(String.class)), 401, response.getStatus()); + } } diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestDeleteSubscriberApi.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestDeleteSubscriberApi.java index 335ca49ec5c8be17b845ad0a2eb585285db31a2e..09bb84c3ae8cad756b1000bd97a4de75c29894f8 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestDeleteSubscriberApi.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestDeleteSubscriberApi.java @@ -16,10 +16,14 @@ package org.opengroup.osdu.register.subscriber; +import static org.junit.Assert.assertEquals; + import org.junit.After; import org.junit.Before; import org.opengroup.osdu.register.util.IBMTestUtils; +import com.sun.jersey.api.client.ClientResponse; + public class TestDeleteSubscriberApi extends DeleteSubscriberApiTest { @Before @@ -33,4 +37,10 @@ public class TestDeleteSubscriberApi extends DeleteSubscriberApiTest { public void tearDown() { this.testUtils = null; } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + ClientResponse response = descriptor.run(getId(), ""); + assertEquals(error(response.getEntity(String.class)), 401, response.getStatus()); + } } diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestGetSubscriberByIdApi.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestGetSubscriberByIdApi.java index 761bcdf7bd8e592970b64a9b2e65481684cd4d4b..c7ea17f5325bab02c724a7437960c8b60864984b 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestGetSubscriberByIdApi.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestGetSubscriberByIdApi.java @@ -16,9 +16,17 @@ package org.opengroup.osdu.register.subscriber; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.junit.After; import org.junit.Before; +import org.opengroup.osdu.register.model.Subscriber; import org.opengroup.osdu.register.util.IBMTestUtils; +import org.opengroup.osdu.register.util.RestDescriptor; + +import com.google.gson.Gson; +import com.sun.jersey.api.client.ClientResponse; public class TestGetSubscriberByIdApi extends GetSubscriberByIdApiTest { @@ -34,4 +42,20 @@ public class TestGetSubscriberByIdApi extends GetSubscriberByIdApiTest { public void tearDown() { this.testUtils = null; } + + @Override + protected void validate20XResponse(ClientResponse response, RestDescriptor descriptor) { + String body = response.getEntity(String.class); + Subscriber subscriber = new Gson().fromJson(body, Subscriber.class); + assertEquals("My test listener.", subscriber.description); + assertTrue(subscriber.createdBy, subscriber.createdBy.endsWith("opengroup.org")); + assertEquals("My listener", subscriber.name); + assertEquals("records-changed", subscriber.topic); + } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + ClientResponse response = descriptor.run(getId(), ""); + assertEquals(error(response.getEntity(String.class)), 401, response.getStatus()); + } } diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestListTopicsApi.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestListTopicsApi.java index 54198bbb142b121fb7e500caf703a7520d9cdaa8..70d5545da901fc08231c7cc6a06114a9419fadea 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestListTopicsApi.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestListTopicsApi.java @@ -16,10 +16,14 @@ package org.opengroup.osdu.register.subscriber; +import static org.junit.Assert.assertEquals; + import org.junit.After; import org.junit.Before; import org.opengroup.osdu.register.util.IBMTestUtils; +import com.sun.jersey.api.client.ClientResponse; + public class TestListTopicsApi extends ListTopicsApiTest { @Before @@ -33,4 +37,10 @@ public class TestListTopicsApi extends ListTopicsApiTest { public void tearDown() { this.testUtils = null; } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + ClientResponse response = descriptor.run(getId(), ""); + assertEquals(error(response.getEntity(String.class)), 401, response.getStatus()); + } } diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestQuerySubscriber.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestQuerySubscriber.java index 33626f90e2f8462a6c8a199efcf45f5b6aa1afde..2185d9d14a94d2e5742123b6f8582c067c6d6a9f 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestQuerySubscriber.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/subscriber/TestQuerySubscriber.java @@ -16,10 +16,14 @@ package org.opengroup.osdu.register.subscriber; +import static org.junit.Assert.assertEquals; + import org.junit.After; import org.junit.Before; import org.opengroup.osdu.register.util.IBMTestUtils; +import com.sun.jersey.api.client.ClientResponse; + public class TestQuerySubscriber extends QuerySubscriberTest { @Before @@ -34,4 +38,10 @@ public class TestQuerySubscriber extends QuerySubscriberTest { public void tearDown() { this.testUtils = null; } + + @Override + public void should_return400_when_makingHttpRequestWithoutToken() throws Exception { + ClientResponse response = descriptor.run(getId(), ""); + assertEquals(error(response.getEntity(String.class)), 401, response.getStatus()); + } } diff --git a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/util/IBMTestUtils.java b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/util/IBMTestUtils.java index 5bcf3228d77d0d99fef9f1362e560f1cd2adbe3b..ed057911348674f100564974cd1de2404674b759 100644 --- a/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/util/IBMTestUtils.java +++ b/testing/register-test-ibm/src/test/java/org/opengroup/osdu/register/util/IBMTestUtils.java @@ -52,7 +52,6 @@ public class IBMTestUtils extends TestUtils { public synchronized String getNoDataAccessToken() throws Exception { if (Strings.isNullOrEmpty(noAccessToken)) { noAccessToken = IdentityClient.getTokenForUserWithNoAccess(); - } return "Bearer " + noAccessToken; }