summaryrefslogtreecommitdiffstats
path: root/local-setup/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'local-setup/src/main/java')
-rw-r--r--local-setup/src/main/java/onap/aai/dto/Model.java93
-rw-r--r--local-setup/src/main/java/onap/aai/dto/ModelGenerator.java48
-rw-r--r--local-setup/src/main/java/onap/aai/util/AaiRequest.java62
-rw-r--r--local-setup/src/main/java/onap/aai/util/Resources.java40
4 files changed, 243 insertions, 0 deletions
diff --git a/local-setup/src/main/java/onap/aai/dto/Model.java b/local-setup/src/main/java/onap/aai/dto/Model.java
new file mode 100644
index 0000000..1cf9a41
--- /dev/null
+++ b/local-setup/src/main/java/onap/aai/dto/Model.java
@@ -0,0 +1,93 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2018-2019 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package onap.aai.dto;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Dummy model for testing purposes
+ */
+@SuppressWarnings("unused")
+public class Model {
+
+ private static final String MODEL_TYPE = "widget";
+ private static final String MODEL_VERSION = "1.0";
+
+ private final String modelInvariantId;
+ private final String modelType;
+ private final ModelVers modelVers;
+
+ public Model(String modelName, String modelInvariantId, String modelVersionId) {
+ this.modelInvariantId = modelInvariantId;
+ this.modelVers = new ModelVers(new ModelVer(modelVersionId, modelName));
+ this.modelType = MODEL_TYPE;
+ }
+
+ public String getModelInvariantId() {
+ return modelInvariantId;
+ }
+
+ public ModelVers getModelVers() {
+ return modelVers;
+ }
+
+ public String getModelType() {
+ return modelType;
+ }
+
+ private static class ModelVers {
+
+ private final List<ModelVer> modelVer;
+
+ ModelVers(ModelVer... modelVer) {
+ this.modelVer = Arrays.asList(modelVer);
+ }
+
+ public List<ModelVer> getModelVer() {
+ return modelVer;
+ }
+ }
+
+ private static class ModelVer {
+
+ private final String modelVersionId;
+ private final String modelVersion;
+ private final String modelName;
+
+ ModelVer(String modelVersionId, String modelName) {
+ this.modelVersionId = modelVersionId;
+ this.modelName = modelName;
+ this.modelVersion = MODEL_VERSION;
+ }
+
+ public String getModelVersionId() {
+ return modelVersionId;
+ }
+
+ public String getModelName() {
+ return modelName;
+ }
+
+ public String getModelVersion() {
+ return MODEL_VERSION;
+ }
+ }
+} \ No newline at end of file
diff --git a/local-setup/src/main/java/onap/aai/dto/ModelGenerator.java b/local-setup/src/main/java/onap/aai/dto/ModelGenerator.java
new file mode 100644
index 0000000..c6625e1
--- /dev/null
+++ b/local-setup/src/main/java/onap/aai/dto/ModelGenerator.java
@@ -0,0 +1,48 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2018-2019 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package onap.aai.dto;
+
+import static onap.aai.util.Resources.readerFrom;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.stream.Stream;
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVParser;
+import org.apache.commons.csv.CSVRecord;
+
+public class ModelGenerator {
+
+ public static Stream<Model> generate(String fileName) {
+ try (CSVParser parser = CSVFormat.DEFAULT.withFirstRecordAsHeader().parse(readerFrom(fileName))) {
+ return parser.getRecords().stream().map(ModelGenerator::csvToModel);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ private static Model csvToModel(CSVRecord csvRecord) {
+ return new Model(
+ csvRecord.get("model-name"),
+ csvRecord.get("model-invariant-id"),
+ csvRecord.get("model-version-id")
+ );
+ }
+}
diff --git a/local-setup/src/main/java/onap/aai/util/AaiRequest.java b/local-setup/src/main/java/onap/aai/util/AaiRequest.java
new file mode 100644
index 0000000..1875e41
--- /dev/null
+++ b/local-setup/src/main/java/onap/aai/util/AaiRequest.java
@@ -0,0 +1,62 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2018-2019 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package onap.aai.util;
+
+import com.github.kevinsawicki.http.HttpRequest;
+
+public class AaiRequest {
+
+ private static final String AAI_BASE_URL = "https://localhost:8443/aai";
+ private static final String AAI_AUTH = "Basic QUFJOkFBSQ==";
+ private static final String SCHEMA_VERSION = "/v14";
+
+ public static HttpRequest get(String endpoint) {
+ return aaiRequest(HttpRequest.get(aaiEndpoint(endpoint)));
+ }
+
+ public static HttpRequest post(String endpoint) {
+ return aaiRequest(HttpRequest.post(aaiEndpoint(endpoint)));
+ }
+
+ public static HttpRequest put(String endpoint) {
+ return aaiRequest(HttpRequest.put(aaiEndpoint(endpoint)));
+ }
+
+ public static HttpRequest delete(String endpoint) {
+ return aaiRequest(HttpRequest.delete(aaiEndpoint(endpoint)));
+ }
+
+ public static String v14(String endpoint) {
+ return SCHEMA_VERSION + endpoint;
+ }
+
+ private static HttpRequest aaiRequest(HttpRequest httpRequest) {
+ return httpRequest
+ .header("X-FromAppId", "dummy id")
+ .header("X-TransactionId", "1234")
+ .authorization(AAI_AUTH)
+ .trustAllCerts()
+ .trustAllHosts();
+ }
+
+ private static String aaiEndpoint(String endpoint) {
+ return AAI_BASE_URL + endpoint;
+ }
+} \ No newline at end of file
diff --git a/local-setup/src/main/java/onap/aai/util/Resources.java b/local-setup/src/main/java/onap/aai/util/Resources.java
new file mode 100644
index 0000000..54d21ec
--- /dev/null
+++ b/local-setup/src/main/java/onap/aai/util/Resources.java
@@ -0,0 +1,40 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2018-2019 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package onap.aai.util;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.stream.Collectors;
+
+public class Resources {
+
+ public static InputStream inputStreamFrom(String fileName) {
+ return Resources.class.getClassLoader().getResourceAsStream(fileName);
+ }
+
+ public static BufferedReader readerFrom(String fileName) {
+ return new BufferedReader(new InputStreamReader(inputStreamFrom(fileName)));
+ }
+
+ public static String rawTextFrom(String fileName) {
+ return readerFrom(fileName).lines().collect(Collectors.joining());
+ }
+}