Skip to content
Snippets Groups Projects
Commit 1aeef4dd authored by Alan Braz's avatar Alan Braz
Browse files

Merge branch 'ibm-int-test-2' into 'master'

Ibm integration test and code changes into master

See merge request !22
parents d6525ad2 bc2cc424
No related branches found
No related tags found
1 merge request!22Ibm integration test and code changes into master
Pipeline #10203 passed
Showing
with 224 additions and 52 deletions
......@@ -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>
......
......@@ -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;
}
}
......@@ -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()));
}
}
......@@ -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
......@@ -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());
}
}
......@@ -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());
}
}
......@@ -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());
}
}
......@@ -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());
}
}
......@@ -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());
}
}
......@@ -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());
}
}
......@@ -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());
}
}
......@@ -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());
}
}
......@@ -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());
}
}
......@@ -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());
}
}
......@@ -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());
}
}
......@@ -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());
}
}
......@@ -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());
}
}
......@@ -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());
}
}
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment