Skip to content
Snippets Groups Projects
Commit 88d060a8 authored by Rustam Lotsmanenko (EPAM)'s avatar Rustam Lotsmanenko (EPAM)
Browse files

Merge branch 'acceptance_tests' into 'master'

Adding Acceptance Tests

See merge request !513
parents dd4f6c94 2233453a
No related branches found
No related tags found
1 merge request!513Adding Acceptance Tests
Pipeline #300750 failed
Showing
with 1248 additions and 0 deletions
......@@ -18,6 +18,7 @@ variables:
AZURE_TEST_SUBDIR: testing/register-test-azure
AZURE_SWAGGER_PATH: api/register/v1/swagger-ui/index.html#/
SERVICE_JAVA_VERSION: "17"
ACCEPTANCE_TEST_DIR: "register-acceptance-test"
include:
- project: "osdu/platform/ci-cd-pipelines"
......
### Running E2E Tests
You will need to have the following environment variables defined.
| name | value | description | sensitive? | source | required |
|-----------------------------|--------------------------------------------------------------|---------------------------------------------------|------------|--------|----------|
| `CLIENT_TENANT` | ex `osdu` | Shared Tenant name | no | - | yes |
| `OSDU_TENANT` | ex `osdu` | OSDU tenant | no | - | yes |
| `REGISTER_BASE_URL` | ex `http://localhost:8080` | Register service Base URL | no | - | yes |
| `REGISTER_CUSTOM_PUSH_URL` | ex `http://localhost:8080/api/register/v1/test/challenge/1 ` | Registration Push URL | no | - | yes |
| `SUBSCRIPTION_ID` | ex `abc` | Subscription used for testing | no | - | yes |
| `SUBSCRIBER_PRIVATE_KEY_ID` | `********` | Subscriber key | yes | - | yes |
| `SUBSCRIBER_SECRET` | `********` | Subscriber secret | yes | - | yes |
| `TEST_TOPIC_NAME` | ex `records-changed` | Event grid topic name, default- 'records-changed' | no | - | no |
Authentication can be provided as OIDC config:
| name | value | description | sensitive? | source |
|-------------------------------------------|--------------------------------------------|-------------------------|------------|--------|
| `EDITOR_OPENID_PROVIDER_CLIENT_ID` | `********` | Editor Client Id | yes | - |
| `EDITOR_OPENID_PROVIDER_CLIENT_SECRET` | `********` | Editor Client secret | yes | - |
| `ADMIN_OPENID_PROVIDER_CLIENT_ID` | `********` | Admin Client Id | yes | - |
| `ADMIN_OPENID_PROVIDER_CLIENT_SECRET` | `********` | Admin Client secret | yes | - |
| `NO_ACCESS_OPENID_PROVIDER_CLIENT_ID` | `********` | No Access Client Id | yes | - |
| `NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET` | `********` | No Access Client secret | yes | - |
| `OPS_OPENID_PROVIDER_CLIENT_ID` | `********` | Ops Client Id | yes | - |
| `OPS_OPENID_PROVIDER_CLIENT_SECRET` | `********` | Ops Client secret | yes | - |
| `TEST_OPENID_PROVIDER_URL` | ex `https://keycloak.com/auth/realms/osdu` | OpenID provider url | yes | - |
Or tokens can be used directly from env variables:
| name | value | description | sensitive? | source |
|-------------------------|------------|-----------------------|------------|--------|
| `EDITOR_TOKEN` | `********` | Editor Token | yes | - |
| `PRIVILEGED_USER_TOKEN` | `********` | Privileged User Token | yes | - |
| `OPS_TOKEN` | `********` | Ops Token | yes | - |
| `NO_ACCESS_USER_TOKEN` | `********` | No Access Token | yes | - |
Execute following command to build code and run all the integration tests:
```bash
# Note: this assumes that the environment variables for integration tests as outlined
# above are already exported in your environment.
# build + install integration test core
$ (cd register-acceptance-test && mvn clean test)
```
## License
Copyright © Google LLC
Copyright © EPAM Systems
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2017-2020 Schlumberger
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.opengroup.osdu.register</groupId>
<artifactId>register-acceptance-test</artifactId>
<version>0.28.0-SNAPSHOT</version>
<packaging>jar</packaging>
<description>Register service Acceptance tests module</description>
<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jackson-databind.version>2.16.1</jackson-databind.version>
<jackson.version>2.16.1</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.json</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19.4</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-gc-spring6</artifactId>
<version>0.26.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-junit_2.12</artifactId>
<version>3.5.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>oauth2-oidc-sdk</artifactId>
<version>9.15</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>${repo.releases.id}</id>
<url>${repo.releases.url}</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>${publish.releases.id}</id>
<url>${publish.releases.url}</url>
</repository>
<snapshotRepository>
<id>${publish.snapshots.id}</id>
<url>${publish.snapshots.url}</url>
</snapshotRepository>
</distributionManagement>
</project>
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.action;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.register.model.Action;
import org.opengroup.osdu.register.util.Config;
import org.opengroup.osdu.register.util.CreateApiTestTemplate;
import org.opengroup.osdu.register.util.RestDescriptor;
import com.sun.jersey.api.client.ClientResponse;
import org.opengroup.osdu.register.util.TestHttpClient;
import static org.junit.Assert.*;
public final class CreateActionApiTest extends CreateApiTestTemplate {
public CreateActionApiTest() {
super(new DeleteActionDescriptor(), new CreateActionDescriptor());
}
@Before
@Override
public void setup() {
this.testUtils = new TestHttpClient();
}
@After
@Override
public void tearDown() {
this.testUtils = null;
}
@Override
protected boolean isDataInTenant() {
return true;
}
@Override
protected void validate20XResponse(ClientResponse response, RestDescriptor descriptor) {
String url = "";
String pushPath = System.getProperty("REGISTER_CUSTOM_PUSH_URL", System.getenv("REGISTER_CUSTOM_PUSH_URL"));
if( Strings.isNullOrEmpty(pushPath)) {
url= Config.Instance().securePushUrl + "api/register/v1/test/challenge";
}
else
{
url = pushPath;
}
String body = response.getEntity(String.class);
Action action = new Gson().fromJson(body, Action.class);
assertEquals("My test listener.", action.description);
assertTrue(action.contactEmail, action.contactEmail.equals("integrationtest@test.com"));
assertEquals("My listener", action.name);
assertEquals(url, action.url);
assertEquals(url, action.img);
assertEquals(1, action.filter.entityType.size());
assertEquals("*", action.filter.entityType.get(0));
assertEquals(1, action.filter.source.size());
assertEquals("*", action.filter.source.get(0));
assertEquals(1, action.filter.version.size());
assertEquals("*", action.filter.version.get(0));
}
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.action;
import com.google.common.base.Strings;
import org.opengroup.osdu.register.util.Config;
import org.opengroup.osdu.register.util.RestDescriptor;
public class CreateActionDescriptor extends RestDescriptor {
@Override
public String getPath() {
return "api/register/v1/action";
}
@Override
public String getHttpMethod() {
return "POST";
}
@Override
public String getValidBody() {
String url = "";
String pushPath = System.getProperty("REGISTER_CUSTOM_PUSH_URL", System.getenv("REGISTER_CUSTOM_PUSH_URL"));
if( Strings.isNullOrEmpty(pushPath)) {
url= Config.Instance().securePushUrl + "api/register/v1/test/challenge";
}
else
{
url = pushPath;
}
return "{\n" +
"\t\"id\": \"" + getArg() + "\",\n" +
"\t\"name\": \"My listener\",\n" +
"\t\"description\": \"My test listener.\",\n" +
"\t\"url\":\"" + url + "\",\n" +
"\t\"img\": \"" + url + "\",\n" +
"\t\"contactEmail\": \"" + "integrationtest@test.com" + "\",\n" +
"\t\"filter\": {\n" +
"\t\"entityType\": [\"*\"],\n" +
"\t\"source\": [\"*\"],\n" +
"\t\"version\": [\"*\"]}\n" +
"}";
}
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.action;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.register.util.DeleteApiTestTemplate;
import org.opengroup.osdu.register.util.TestHttpClient;
public final class DeleteActionApiTest extends DeleteApiTestTemplate {
public DeleteActionApiTest() {
super(new DeleteActionDescriptor(), new CreateActionDescriptor());
}
@Before
@Override
public void setup() {
this.testUtils = new TestHttpClient();
}
@After
@Override
public void tearDown() {
this.testUtils = null;
}
@Override
protected boolean isDataInTenant() {
return true;
}
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.action;
import org.opengroup.osdu.register.util.RestDescriptor;
public class DeleteActionDescriptor extends RestDescriptor {
@Override
public String getPath() {
return "api/register/v1/action/" + getArg();
}
@Override
public String getHttpMethod() {
return "DELETE";
}
@Override
public String getValidBody() {
return "";
}
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.action;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.register.model.Action;
import org.opengroup.osdu.register.util.Config;
import org.opengroup.osdu.register.util.RestDescriptor;
import org.opengroup.osdu.register.util.RetrieveApiTestTemplate;
import com.sun.jersey.api.client.ClientResponse;
import org.opengroup.osdu.register.util.TestHttpClient;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public final class GetActionByIdApiTest extends RetrieveApiTestTemplate {
public GetActionByIdApiTest() {
super(new GetActionDescriptor(), new DeleteActionDescriptor(), new CreateActionDescriptor());
}
@Before
@Override
public void setup() {
this.testUtils = new TestHttpClient();
}
@After
@Override
public void tearDown() {
this.testUtils = null;
}
@Override
protected boolean isDataInTenant() {
return true;
}
@Override
protected void validate20XResponse(ClientResponse response, RestDescriptor descriptor) {
// String url = Config.Instance().securePushUrl + "api/register/v1/test/challenge";
String url = "";
String pushPath = System.getProperty("REGISTER_CUSTOM_PUSH_URL", System.getenv("REGISTER_CUSTOM_PUSH_URL"));
if( Strings.isNullOrEmpty(pushPath)) {
url= Config.Instance().securePushUrl + "api/register/v1/test/challenge";
}
else
{
url = pushPath;
}
String body = response.getEntity(String.class);
Action action = new Gson().fromJson(body, Action.class);
assertEquals("My test listener.", action.description);
assertTrue(action.contactEmail, action.contactEmail.equals("integrationtest@test.com"));
assertEquals("My listener", action.name);
assertEquals(url, action.url);
assertEquals(url, action.img);
assertEquals(1, action.filter.entityType.size());
assertEquals("*", action.filter.entityType.get(0));
assertEquals(1, action.filter.source.size());
assertEquals("*", action.filter.source.get(0));
assertEquals(1, action.filter.version.size());
assertEquals("*", action.filter.version.get(0));
}
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.action;
import org.opengroup.osdu.register.util.RestDescriptor;
public class GetActionDescriptor extends RestDescriptor {
@Override
public String getPath() {
return "api/register/v1/action/" + getArg();
}
@Override
public String getHttpMethod() {
return "GET";
}
@Override
public String getValidBody() {
return "";
}
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.action;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.register.util.BaseTestTemplate;
import org.opengroup.osdu.register.util.RestDescriptor;
import com.sun.jersey.api.client.ClientResponse;
import org.opengroup.osdu.register.util.TestHttpClient;
public final class RetrieveActionApiTest extends BaseTestTemplate {
protected RestDescriptor createDescriptor;
protected RestDescriptor deleteDescriptor;
private String id = "retrieveactiontest" + System.currentTimeMillis();
public RetrieveActionApiTest() {
super(new RetrieveActionDescriptor());
this.createDescriptor = new CreateActionDescriptor();
this.deleteDescriptor = new DeleteActionDescriptor();
}
@Before
@Override
public void setup() {
this.testUtils = new TestHttpClient();
}
@After
@Override
public void tearDown() {
this.testUtils = null;
}
@Override
protected boolean isDataInTenant() {
return true;
}
@Override
protected String getId() {
return id;
}
@Override
protected void validate20XResponse(ClientResponse response, RestDescriptor descriptor) {
}
@Override
protected void deleteResource() throws Exception {
deleteDescriptor.run(getId(), testUtils.getOpsAccessToken());
}
@Override
protected void deleteResourcewitharg(String ext) throws Exception {
//do nothing
}
@Override
protected void createResource() throws Exception {
createDescriptor.run(getId(), testUtils.getOpsAccessToken());
}
@Override
protected void createResourcewitharg(String ext) throws Exception {
createDescriptor.run(ext, testUtils.getOpsAccessToken());
}
@Override
protected int expectedOkResponseCode() {
return 200;
}
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.action;
import org.opengroup.osdu.register.util.RestDescriptor;
public class RetrieveActionDescriptor extends RestDescriptor {
@Override
public String getPath() {
return "api/register/v1/action:retrieve";
}
@Override
public String getHttpMethod() {
return "POST";
}
@Override
public String getValidBody() {
String kind = "tenant1:source:type:1.0.0";
return "{\n" +
"\t\"id\": \"" + getArg() + "\",\n" +
"\t\"kind\": \"" + kind + "\",\n" +
"\t\"data\": {\n" +
"\t\"msg\": \"hello\"\n}" +
"}";
}
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.action;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.register.model.ParsedAction;
import org.opengroup.osdu.register.model.TestPayload;
import org.opengroup.osdu.register.model.ValidationErrorResponse;
import org.opengroup.osdu.register.util.TestBase;
import org.opengroup.osdu.register.util.TestPayloadReader;
import org.opengroup.osdu.register.util.TestHttpClient;
import org.opengroup.osdu.register.util.TestUtils;
import com.sun.jersey.api.client.ClientResponse;
import org.apache.http.HttpStatus;
import org.junit.Test;
import javax.ws.rs.HttpMethod;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.Assert.*;
public final class TestActionApiTest extends TestBase {
private static final String PATH = "api/register/v1/action:test";
private TestPayloadReader reader = new TestPayloadReader();
@Before
@Override
public void setup() {
this.testUtils = new TestHttpClient();
}
@After
@Override
public void tearDown() {
this.testUtils = null;
}
@Test
public void should_return20X_when_usingCredentialsWithPermission() throws Exception {
String validPayload = reader.getTestPayload("actionApi/validTestAction.json");
ClientResponse response = TestUtils.send(PATH, HttpMethod.POST, testUtils.getOpsAccessToken(), validPayload, "");
assertEquals(HttpStatus.SC_OK, response.getStatus());
String body = response.getEntity(String.class);
ParsedAction parsedAction = new Gson().fromJson(body, ParsedAction.class);
assertEquals("https://myapp.osdu.opengroup.org/action/abc123", parsedAction.url);
assertTrue(Strings.isNullOrEmpty(parsedAction.errors));
}
@Test
public void should_return40XResponseCode_when_makingRequest_withInvalidPayload() throws Exception {
List<TestPayload> payloadList = new ArrayList<>();
payloadList.add(TestPayload.builder()
.expectedErrors(Arrays.asList("action.url must be a valid URL", "testPayload must not be null"))
.payloadFileName("actionApi/invalidUrlTestActionPayload.json").build());
payloadList.add(TestPayload.builder()
.expectedErrors(Arrays.asList("action.url must be a valid URL"))
.payloadFileName("actionApi/nonHttpsTestAction.json").build());
payloadList.add(TestPayload.builder()
.expectedErrors(Arrays.asList("action.filter Found empty filter values. Must provide a filter value. Use '*' if you want to match all values for a filter property."))
.payloadFileName("actionApi/invalidFilterEntityTypeTestAction.json").build());
payloadList.add(TestPayload.builder()
.expectedErrors(Arrays.asList("action.name must match \"^[A-Za-z0-9- ]{2,50}\"", "action.name must not be empty"))
.payloadFileName("actionApi/invalidNameTestAction.json").build());
for (TestPayload payload : payloadList) {
makeRequestWithInvalidPayload(payload.getExpectedErrors(), payload.getPayloadFileName());
}
}
public void makeRequestWithInvalidPayload(List<String> expectedErrors, String payloadFileName) throws Exception {
String payload = reader.getTestPayload(payloadFileName);
ClientResponse response = TestUtils.send(PATH, HttpMethod.POST, testUtils.getOpsAccessToken(), payload, "");
assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus());
String body = response.getEntity(String.class);
ValidationErrorResponse validationErrorResponse = new Gson().fromJson(body, ValidationErrorResponse.class);
List<String> actualErrors = new Gson().fromJson(validationErrorResponse.getMessage(), new TypeToken<List<String>>() {
}.getType());
assertThat(expectedErrors, containsInAnyOrder(actualErrors.toArray()));
}
}
/*
Copyright 2002-2022 Google LLC
Copyright 2002-2022 EPAM Systems, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.opengroup.osdu.register.config;
import com.nimbusds.oauth2.sdk.http.HTTPRequest;
import com.nimbusds.oauth2.sdk.http.HTTPResponse;
import com.nimbusds.oauth2.sdk.id.Issuer;
import com.nimbusds.openid.connect.sdk.op.OIDCProviderConfigurationRequest;
import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata;
public class OpenIDProviderConfig {
private String opsClientId;
private String opsClientSecret;
private String adminClientId;
private String adminClientSecret;
private String editorClientId;
private String editorClientSecret;
private String noAccessClientId;
private String noAccessClientSecret;
private String url;
private final String[] scopes = {"openid"};
private static final OpenIDProviderConfig openIDProviderConfig = new OpenIDProviderConfig();
private static OIDCProviderMetadata providerMetadata;
public static OpenIDProviderConfig Instance() {
try {
openIDProviderConfig.opsClientId = System.getProperty("OPS_OPENID_PROVIDER_CLIENT_ID",
System.getenv("OPS_OPENID_PROVIDER_CLIENT_ID"));
openIDProviderConfig.opsClientSecret = System.getProperty(
"OPS_OPENID_PROVIDER_CLIENT_SECRET",
System.getenv("OPS_OPENID_PROVIDER_CLIENT_SECRET"));
openIDProviderConfig.adminClientId = System.getProperty(
"ADMIN_OPENID_PROVIDER_CLIENT_ID",
System.getenv("ADMIN_OPENID_PROVIDER_CLIENT_ID"));
openIDProviderConfig.adminClientSecret = System.getProperty(
"ADMIN_OPENID_PROVIDER_CLIENT_SECRET",
System.getenv("ADMIN_OPENID_PROVIDER_CLIENT_SECRET"));
openIDProviderConfig.editorClientId = System.getProperty(
"EDITOR_OPENID_PROVIDER_CLIENT_ID",
System.getenv("EDITOR_OPENID_PROVIDER_CLIENT_ID"));
openIDProviderConfig.editorClientSecret = System.getProperty(
"EDITOR_OPENID_PROVIDER_CLIENT_SECRET",
System.getenv("EDITOR_OPENID_PROVIDER_CLIENT_SECRET"));
openIDProviderConfig.noAccessClientId = System.getProperty(
"NO_ACCESS_OPENID_PROVIDER_CLIENT_ID",
System.getenv("NO_ACCESS_OPENID_PROVIDER_CLIENT_ID"));
openIDProviderConfig.noAccessClientSecret = System.getProperty(
"NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET",
System.getenv("NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET"));
openIDProviderConfig.url =
System.getProperty("TEST_OPENID_PROVIDER_URL", System.getenv("TEST_OPENID_PROVIDER_URL"));
Issuer issuer = new Issuer(openIDProviderConfig.url);
OIDCProviderConfigurationRequest request = new OIDCProviderConfigurationRequest(issuer);
HTTPRequest httpRequest = request.toHTTPRequest();
HTTPResponse httpResponse = httpRequest.send();
providerMetadata = OIDCProviderMetadata.parse(httpResponse.getContentAsJSONObject());
} catch (Exception e) {
throw new RuntimeException("Malformed token provider configuration", e);
}
return openIDProviderConfig;
}
public String getOpsClientId() {
return opsClientId;
}
public String getOpsClientSecret() {
return opsClientSecret;
}
public String getAdminClientId() {
return adminClientId;
}
public String getAdminClientSecret() {
return adminClientSecret;
}
public String getEditorClientId() {
return editorClientId;
}
public String getEditorClientSecret() {
return editorClientSecret;
}
public String getNoAccessClientId() {
return noAccessClientId;
}
public String getNoAccessClientSecret() {
return noAccessClientSecret;
}
public String getUrl() {
return url;
}
public String[] getScopes() {
return scopes;
}
public OIDCProviderMetadata getProviderMetadata() {
return providerMetadata;
}
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.ddms;
import org.opengroup.osdu.register.util.Config;
import org.opengroup.osdu.register.util.RestDescriptor;
import org.opengroup.osdu.register.util.TestPayloadReader;
public class CreateDdmsDescriptor extends RestDescriptor {
private final TestPayloadReader reader = new TestPayloadReader();
@Override
public String getPath() {
return "api/register/v1/ddms";
}
@Override
public String getHttpMethod() {
return "POST";
}
@Override
public String getValidBody() {
return reader.getCreateRequestPayload("createDdmsApi/validCreateDdmsRequestBody.json", getArg(), Config.Instance().OsduTenant);
}
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.ddms;
import com.google.gson.Gson;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.register.model.Ddms;
import org.opengroup.osdu.register.util.CreateApiTestTemplate;
import org.opengroup.osdu.register.util.RestDescriptor;
import com.sun.jersey.api.client.ClientResponse;
import org.opengroup.osdu.register.util.TestHttpClient;
import static org.junit.Assert.*;
public final class CreateRegistrationApiTest extends CreateApiTestTemplate {
public CreateRegistrationApiTest() {
super(new DeleteDdmsDescriptor(), new CreateDdmsDescriptor());
}
@Before
@Override
public void setup() {
this.testUtils = new TestHttpClient();
}
@After
@Override
public void tearDown() {
this.testUtils = null;
}
@Override
protected boolean isDataInTenant() {
return true;
}
@Override
protected void validate20XResponse(ClientResponse response, RestDescriptor descriptor) {
String body = response.getEntity(String.class);
Ddms ddms = new Gson().fromJson(body, Ddms.class);
assertEquals(getId(), ddms.id);
assertEquals("My test ddms.", ddms.description);
assertTrue(ddms.contactEmail, ddms.contactEmail.equals("test@test.com"));
assertNotNull(ddms.createdDateTimeEpoch);
assertEquals("logDDMS", ddms.name);
assertEquals(1, ddms.interfaces.size());
assertEquals("wellbore", ddms.interfaces.iterator().next().entityType);
}
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.ddms;
import org.opengroup.osdu.register.util.RestDescriptor;
public class DeleteDdmsDescriptor extends RestDescriptor {
@Override
public String getPath() {
return "api/register/v1/ddms/" + getArg();
}
@Override
public String getHttpMethod() {
return "DELETE";
}
@Override
public String getValidBody() {
return "";
}
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.ddms;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.register.util.DeleteApiTestTemplate;
import org.opengroup.osdu.register.util.TestHttpClient;
public final class DeleteRegistrationApiTest extends DeleteApiTestTemplate {
public DeleteRegistrationApiTest() {
super(new DeleteDdmsDescriptor(), new CreateDdmsDescriptor());
}
@Before
@Override
public void setup() {
this.testUtils = new TestHttpClient();
}
@After
@Override
public void tearDown() {
this.testUtils = null;
}
@Override
protected boolean isDataInTenant() {
return true;
}
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.ddms;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.register.util.ConsumptionApiTemplate;
import org.opengroup.osdu.register.util.TestHttpClient;
public final class GetConsumptionByIdApiTest extends ConsumptionApiTemplate {
public GetConsumptionByIdApiTest() {
super(new GetRedirectEndpointByIdDescriptor(), new DeleteDdmsDescriptor(), new CreateDdmsDescriptor());
}
@Before
@Override
public void setup() {
this.testUtils = new TestHttpClient();
}
@After
@Override
public void tearDown() {
this.testUtils = null;
}
@Override
protected boolean isDataInTenant() {
return true;
}
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.ddms;
import org.opengroup.osdu.register.util.RestDescriptor;
public class GetDdmsByIdDescriptor extends RestDescriptor {
@Override
public String getPath() {
return "api/register/v1/ddms/" + getArg();
}
@Override
public String getHttpMethod() {
return "GET";
}
@Override
public String getValidBody() {
return "";
}
}
\ No newline at end of file
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.register.ddms;
import org.opengroup.osdu.register.util.RestDescriptor;
public class GetRedirectEndpointByIdDescriptor extends RestDescriptor {
private static long NOW;
private static String TENANT_ID;
@Override
public String getPath() {
return String.format("api/register/v1/ddms/%s/%s/%s", getArg(), getType(), getLocalId());
}
@Override
public String getHttpMethod() {
return "GET";
}
@Override
public String getValidBody() {
return "";
}
public String getType() {
return "wellbore";
}
public String getLocalId() {
NOW = System.currentTimeMillis();
TENANT_ID = System.getProperty("OSDU_TENANT", System.getenv("OSDU_TENANT"));
if (TENANT_ID == null) {
TENANT_ID = "opendes";
}
return TENANT_ID + ":test:1.1." + NOW;
}
}
\ No newline at end of file
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