aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common
diff options
context:
space:
mode:
authorAmichai Hemli <amichai.hemli@intl.att.com>2019-09-25 12:43:31 +0000
committerGerrit Code Review <gerrit@onap.org>2019-09-25 12:43:31 +0000
commitde6b7cc7244722bf984a0d7cb7070fe568614df6 (patch)
treeb94670de486ff3472b93d1f8a142aa0be40cc8df /vid-app-common
parent41c8e5685b70387c203b4c225a1573697d28b6d1 (diff)
parent6cd75d40eb608e2cd488bc4141b5b4e341b49068 (diff)
Merge "Test Administration Script: category_parameter.sh"
Diffstat (limited to 'vid-app-common')
-rwxr-xr-x[-rw-r--r--]vid-app-common/src/main/resources/scripts/category_parameter.sh0
-rwxr-xr-x[-rw-r--r--]vid-app-common/src/main/resources/scripts/update_category_option_name.sh0
-rwxr-xr-x[-rw-r--r--]vid-app-common/src/main/resources/scripts/vnf_wf.sh0
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/scripts/AdministrationScriptsTest.java140
4 files changed, 140 insertions, 0 deletions
diff --git a/vid-app-common/src/main/resources/scripts/category_parameter.sh b/vid-app-common/src/main/resources/scripts/category_parameter.sh
index 0ff1c73c3..0ff1c73c3 100644..100755
--- a/vid-app-common/src/main/resources/scripts/category_parameter.sh
+++ b/vid-app-common/src/main/resources/scripts/category_parameter.sh
diff --git a/vid-app-common/src/main/resources/scripts/update_category_option_name.sh b/vid-app-common/src/main/resources/scripts/update_category_option_name.sh
index 5ff505800..5ff505800 100644..100755
--- a/vid-app-common/src/main/resources/scripts/update_category_option_name.sh
+++ b/vid-app-common/src/main/resources/scripts/update_category_option_name.sh
diff --git a/vid-app-common/src/main/resources/scripts/vnf_wf.sh b/vid-app-common/src/main/resources/scripts/vnf_wf.sh
index 69cb595b5..69cb595b5 100644..100755
--- a/vid-app-common/src/main/resources/scripts/vnf_wf.sh
+++ b/vid-app-common/src/main/resources/scripts/vnf_wf.sh
diff --git a/vid-app-common/src/test/java/org/onap/vid/scripts/AdministrationScriptsTest.java b/vid-app-common/src/test/java/org/onap/vid/scripts/AdministrationScriptsTest.java
new file mode 100644
index 000000000..ddd28fd82
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/scripts/AdministrationScriptsTest.java
@@ -0,0 +1,140 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T 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 org.onap.vid.scripts;
+
+
+import static com.xebialabs.restito.builder.stub.StubHttp.whenHttp;
+import static com.xebialabs.restito.builder.verify.VerifyHttp.verifyHttp;
+import static com.xebialabs.restito.semantics.Action.ok;
+import static com.xebialabs.restito.semantics.Action.stringContent;
+import static com.xebialabs.restito.semantics.Condition.post;
+import static com.xebialabs.restito.semantics.Condition.withHeader;
+import static com.xebialabs.restito.semantics.Condition.withPostBodyContaining;
+import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;
+import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
+import static java.text.MessageFormat.format;
+import static org.hamcrest.CoreMatchers.allOf;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import com.google.common.collect.ImmutableList;
+import com.xebialabs.restito.semantics.Applicable;
+import com.xebialabs.restito.semantics.Condition;
+import com.xebialabs.restito.server.StubServer;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.regex.Pattern;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.testng.annotations.Test;
+
+public class AdministrationScriptsTest {
+
+ @Test
+ public void categoryParameterSh_addReleaseCategory_PostAsExpected() throws Exception {
+ final StubServer stubServer = new StubServer();
+ final URI scriptSource = AdministrationScriptsTest.class
+ .getResource("/scripts/category_parameter.sh").toURI();
+
+ stubServer.start();
+
+ try {
+
+ // given
+ Condition[] expectedRequest = {
+ post("/vid/maintenance/category_parameter/release"),
+ withHeader("Content-Type", "application/json"),
+ withPostBodyContaining(asSpacedRegex("{ \"options\" : [ \"2019.08\" ] }"))
+ };
+
+ String responseBody = "stubbed response body";
+ Applicable[] stubbedResponse = {ok(), stringContent(responseBody)};
+
+ whenHttp(stubServer).match(expectedRequest).then(stubbedResponse);
+
+ // when
+ Path script = copyToTempFile(scriptSource);
+ Path input = createTempFile("2019.08");
+
+ Pair<Integer, String> result = exec(
+ format("sed -i s/8080/{0}/g {1}", String.valueOf(stubServer.getPort()), path(script)),
+ format("chmod +x {0}", path(script)),
+ format("{0} -o ADD -p {1} -c release", path(script), path(input))
+ );
+
+ // then
+ assertThat("output is descriptive", result.getRight(), allOf(
+ containsString("Sending request:"),
+ containsString("wget output:"),
+ containsString(responseBody)
+ ));
+ assertThat("error code is 0", result.getLeft(), is(0));
+ verifyHttp(stubServer).once(expectedRequest);
+
+ } finally {
+ stubServer.stop();
+ }
+ }
+
+ private Path createTempFile(String text) throws IOException {
+ Path input = Files.createTempFile("input", ".txt");
+ return Files.write(input, ImmutableList.of(text));
+ }
+
+ private Path copyToTempFile(URI scriptSource) throws IOException {
+ Path script = Files.createTempFile("script", ".sh");
+ Files.copy(Paths.get(scriptSource), script, COPY_ATTRIBUTES, REPLACE_EXISTING);
+ return script;
+ }
+
+ private String path(Path filePath) {
+ return filePath.toUri().getPath();
+ }
+
+ private Pattern asSpacedRegex(String string) {
+ final String spaces = "\\s*";
+ return Pattern.compile(""
+ + spaces
+ + string
+ .replaceAll("([\\[\\]{}\\(\\).])", "\\\\$0") // add an escaping-slash before any bracket or dot
+ .replace(" ", spaces) // allow 0 or more spaces anywhere
+ + spaces
+ );
+ }
+
+ private Pair<Integer, String> exec(String... cmds) throws IOException, InterruptedException {
+ String cmd = "" + String.join(" && ", cmds) + "";
+ Process process = Runtime.getRuntime().exec(new String[]{"sh", "-c", cmd});
+
+ int exitCode = process.waitFor();
+ String output = IOUtils.toString(
+ exitCode == 0 ? process.getInputStream() : process.getErrorStream(), Charset.defaultCharset());
+
+ return ImmutablePair.of(exitCode, cmd + ": " + output);
+ }
+
+}