Skip to content
Snippets Groups Projects
Commit 5e61379e authored by Isha Kumari's avatar Isha Kumari
Browse files

Revert "Test Cases failure fixes."

This reverts commit a5152781.
parent a5152781
No related branches found
No related tags found
1 merge request!378Test Cases failure fixes
Pipeline #200419 failed
Showing
with 209 additions and 18 deletions
......@@ -42,6 +42,11 @@ public class TestCreateActionApi extends CreateActionApiTest {
public void should_return400_when_makingHttpRequestWithoutToken() throws Exception {
ClientResponse response = descriptor.run(getId(), "");
assertEquals(error(response.getEntity(String.class)), 403, response.getStatus());
}
}
@Override
public void should_return401_when_noAccessOnCustomerTenantOps()throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(getId(), testUtils.getNoDataAccessToken());
assertEquals(error(response.getEntity(String.class)), 401, response.getStatus());
}
}
......@@ -52,9 +52,13 @@ public class TestDeleteActionApi extends DeleteActionApiTest {
public void should_beAbleToRunApiInParallel() throws Exception {
// Ignoring as this test case failing sometimes
super.should_beAbleToRunApiInParallel();
}
}
@Test
@Override
public void should_return401_when_noAccessOnCustomerTenantOps() throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(getId(), testUtils.getNoDataAccessToken());
assertEquals(error(response.getEntity(String.class)), 401, response.getStatus());
}
}
......@@ -42,5 +42,10 @@ public class TestGetActionByIdApi extends GetActionByIdApiTest {
public void should_return400_when_makingHttpRequestWithoutToken() throws Exception {
ClientResponse response = descriptor.run(getId(), "");
assertEquals(error(response.getEntity(String.class)), 403, response.getStatus());
}
}
@Override
public void should_return401_when_noAccessOnCustomerTenantOps()throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(getId(), testUtils.getNoDataAccessToken());
assertEquals(error(response.getEntity(String.class)), 401, response.getStatus());
}
}
......@@ -43,4 +43,9 @@ public class TestCreateRegistrationApi extends CreateRegistrationApiTest {
ClientResponse response = descriptor.run(getId(), "");
assertEquals(error(response.getEntity(String.class)), 403, response.getStatus());
}
@Override
public void should_return401_when_noAccessOnCustomerTenantOps()throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(getId(), testUtils.getNoDataAccessToken());
assertEquals(error(response.getEntity(String.class)), 401, response.getStatus());
}
}
......@@ -43,6 +43,10 @@ public class TestDeleteRegistrationApi extends DeleteRegistrationApiTest {
ClientResponse response = descriptor.run(getId(), "");
assertEquals(error(response.getEntity(String.class)), 403, response.getStatus());
}
@Override
public void should_return401_when_noAccessOnCustomerTenantOps()throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(getId(), testUtils.getNoDataAccessToken());
assertEquals(error(response.getEntity(String.class)), 401, response.getStatus());
}
}
......@@ -43,6 +43,10 @@ public class TestGetConsumptionByIdApi extends GetConsumptionByIdApiTest {
ClientResponse response = descriptor.run(getId(), "");
assertEquals(error(response.getEntity(String.class)), 403, response.getStatus());
}
@Override
public void should_return401_when_noAccessOnCustomerTenantOps()throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(getId(), testUtils.getNoDataAccessToken());
assertEquals(error(response.getEntity(String.class)), 401, response.getStatus());
}
}
......@@ -44,5 +44,10 @@ public class TestGetRegistrationByIdApi extends GetRegistrationByIdApiTest {
ClientResponse response = descriptor.run(getId(), "");
assertEquals(error(response.getEntity(String.class)), 403, response.getStatus());
}
@Override
public void should_return401_when_noAccessOnCustomerTenantOps()throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(getId(), testUtils.getNoDataAccessToken());
assertEquals(error(response.getEntity(String.class)), 401, response.getStatus());
}
}
......@@ -43,4 +43,9 @@ public class TestQueryDdmsByType extends QueryDdmsByTypeTest {
ClientResponse response = descriptor.run(getId(), "");
assertEquals(error(response.getEntity(String.class)), 403, response.getStatus());
}
@Override
public void should_return401_when_noAccessOnCustomerTenantOps()throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(getId(), testUtils.getNoDataAccessToken());
assertEquals(error(response.getEntity(String.class)), 401, response.getStatus());
}
}
......@@ -19,9 +19,10 @@ 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 java.util.Base64;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.opengroup.osdu.register.model.Subscriber;
import org.opengroup.osdu.register.util.Config;
import org.opengroup.osdu.register.util.IBMTestUtils;
......@@ -30,7 +31,17 @@ 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;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class TestCreateSubscriberApi extends CreateSubscriberApiTest {
@Before
......@@ -63,4 +74,51 @@ public class TestCreateSubscriberApi extends CreateSubscriberApiTest {
ClientResponse response = descriptor.run(getId(), "");
assertEquals(error(response.getEntity(String.class)), 403, response.getStatus());
}
@Override
public void should_return401_when_noAccessOnCustomerTenantOps()throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(getId(), testUtils.getNoDataAccessToken());
assertEquals(error(response.getEntity(String.class)), 401, response.getStatus());
}
@Test
@Override
public void should_onlyCreateMax1Resource_and_return409ForTheRest_when_creatingTheSameResourceInParallel() throws Exception {
ExecutorService executor = Executors.newFixedThreadPool(8);
List<Callable<ClientResponse>> tasks = new ArrayList<>();
for (int i = 0; i < 8; i++) {
Callable<ClientResponse> task = () -> {
try {
return descriptor.run(getId(), testUtils.getOpsAccessToken());
} catch (Exception ex) {
return null;
}
};
tasks.add(task);
}
List<Future<ClientResponse>> responses = executor.invokeAll(tasks);
executor.shutdown();
executor.awaitTermination(300, TimeUnit.SECONDS);
int sucessResponseCount = 0;
for (Future<ClientResponse> future : responses) {
if (future.get().getStatus() == expectedOkResponseCode())
sucessResponseCount++;
}
deleteResource();
assertTrue(error("Expected 1 successful response. Actual " + sucessResponseCount), sucessResponseCount <= 1);
}
@Test
public void should_return20XResponseCode_when_makingValidHttpsRequest() throws Exception {
createResource();
ClientResponse response = descriptor.run(getId(), testUtils.getOpsAccessToken());
deleteResource();
assertEquals(error(""), expectedOkResponseCode(), response.getStatus());
validate20XResponse(response, descriptor);
}
}
......@@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.opengroup.osdu.register.util.IBMTestUtils;
import com.sun.jersey.api.client.ClientResponse;
......@@ -43,4 +45,19 @@ public class TestDeleteSubscriberApi extends DeleteSubscriberApiTest {
ClientResponse response = descriptor.run(getId(), "");
assertEquals(error(response.getEntity(String.class)), 403, response.getStatus());
}
@Override
public void should_return401_when_noAccessOnCustomerTenantOps()throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(getId(), testUtils.getNoDataAccessToken());
assertEquals(error(response.getEntity(String.class)), 401, response.getStatus());
}
@Test
@Override
@Ignore("Unstable test")
public void should_return20XResponseCode_when_makingValidHttpsRequest() throws Exception {
createResource();
ClientResponse response = descriptor.run(getId(), testUtils.getOpsAccessToken());
deleteResource();
assertEquals(error(""), expectedOkResponseCode(), response.getStatus());
validate20XResponse(response, descriptor);
}
}
......@@ -16,18 +16,26 @@
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.junit.Ignore;
import org.junit.Test;
import org.opengroup.osdu.register.model.Subscriber;
import org.opengroup.osdu.register.util.IBMTestUtils;
import org.opengroup.osdu.register.util.RestDescriptor;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import com.google.gson.Gson;
import com.sun.jersey.api.client.ClientResponse;
import static org.junit.Assert.*;
public class TestGetSubscriberByIdApi extends GetSubscriberByIdApiTest {
@Before
......@@ -52,10 +60,60 @@ public class TestGetSubscriberByIdApi extends GetSubscriberByIdApiTest {
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)), 403, response.getStatus());
}
@Test
@Override
public void should_beAbleToRunApiInParallel() throws Exception {
createResource();
ExecutorService executor = Executors.newFixedThreadPool(10);
List<Callable<ClientResponse>> tasks = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Callable<ClientResponse> task = () -> {
try {
return descriptor.run(getId(), testUtils.getOpsAccessToken());
} catch (Exception ex) {
return null;
}
};
tasks.add(task);
}
List<Future<ClientResponse>> responses = executor.invokeAll(tasks);
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
deleteResource();
int sucessResponseCount = 0;
int errorResponseCount = 0;
for (Future<ClientResponse> future : responses) {
if (future.get().getStatus() == expectedOkResponseCode())
sucessResponseCount++;
else
errorResponseCount++;
}
deleteResource();
assertEquals(error("Expected all successful responses. Actual " + sucessResponseCount), 10, sucessResponseCount);
}
@Override
public void should_return401_when_noAccessOnCustomerTenantOps()throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(getId(), testUtils.getNoDataAccessToken());
assertEquals(error(response.getEntity(String.class)), 401, response.getStatus());
}
@Test
@Override
@Ignore("Unstable test")
public void should_return20XResponseCode_when_makingValidHttpsRequest() throws Exception {
createResource();
ClientResponse response = descriptor.run(getId(), testUtils.getOpsAccessToken());
deleteResource();
assertEquals(error(""), expectedOkResponseCode(), response.getStatus());
validate20XResponse(response, descriptor);
}
}
......@@ -20,8 +20,13 @@ import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.opengroup.osdu.register.util.IBMTestUtils;
import org.opengroup.osdu.register.util.Config;
import java.util.Base64;
import com.sun.jersey.api.client.ClientResponse;
public class TestQuerySubscriber extends QuerySubscriberTest {
......@@ -44,4 +49,20 @@ public class TestQuerySubscriber extends QuerySubscriberTest {
ClientResponse response = descriptor.run(getId(), "");
assertEquals(error(response.getEntity(String.class)), 403, response.getStatus());
}
@Test
@Override
public void should_return401_when_noAccessOnCustomerTenantOps() throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(getId(), testUtils.getNoDataAccessToken());
assertEquals(error(response.getEntity(String.class)), 401, response.getStatus());
}
@Test
@Override
public void should_return20XResponseCode_when_makingValidHttpsRequest() throws Exception {
createResource();
ClientResponse response = descriptor.run(getId(), testUtils.getOpsAccessToken());
deleteResource();
assertEquals(error(""), expectedOkResponseCode(), response.getStatus());
validate20XResponse(response, descriptor);
}
}
......@@ -33,7 +33,7 @@ public class IBMTestUtils extends TestUtils {
@Override
public synchronized String getAdmAccessToken() throws Exception {
if (Strings.isNullOrEmpty(admToken)) {
admToken = IdentityClient.getTokenForUserWithAccess();
admToken = IdentityClient.getTokenForUserWithNoAccess();
}
return "Bearer " + admToken;
......@@ -42,7 +42,7 @@ public class IBMTestUtils extends TestUtils {
@Override
public synchronized String getEditorAccessToken() throws Exception {
if (Strings.isNullOrEmpty(editorToken)) {
editorToken = IdentityClient.getTokenForUserWithAccess();
editorToken = IdentityClient.getTokenForUserWithNoAccess();
}
return "Bearer " + editorToken;
......
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