summaryrefslogtreecommitdiffstats
path: root/common-app-api/src/test/java/org
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2023-06-02 11:38:36 +0000
committerVasyl Razinkov <vasyl.razinkov@est.tech>2023-06-02 16:21:12 +0000
commit222555c7995645416a47bc52ed8837e3afde8e21 (patch)
tree0eae25247dfbc06538a9170dc5ab9a8addeb5bb3 /common-app-api/src/test/java/org
parent9fb750f15ee84c4318d729c91c4ba50b61d73b3e (diff)
Revert "Support SIP TLS"
This reverts commit a2feaf9b65cbba66181fb560b5815a62427d65cc. Reason for revert: deployment issue Change-Id: Ic21e213493f51d0c11778187ab054881bba7c21e Issue-ID: SDC-4483 Signed-off-by: MichaelMorris <michael.morris@est.tech>
Diffstat (limited to 'common-app-api/src/test/java/org')
-rw-r--r--common-app-api/src/test/java/org/openecomp/sdc/common/http/client/api/HttpClientFactoryTest.java16
-rw-r--r--common-app-api/src/test/java/org/openecomp/sdc/common/http/client/api/HttpResponseTest.java26
-rw-r--r--common-app-api/src/test/java/org/openecomp/sdc/common/util/StreamUtilsTests.java142
3 files changed, 163 insertions, 21 deletions
diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/http/client/api/HttpClientFactoryTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/http/client/api/HttpClientFactoryTest.java
index feb49d0cc8..4958202811 100644
--- a/common-app-api/src/test/java/org/openecomp/sdc/common/http/client/api/HttpClientFactoryTest.java
+++ b/common-app-api/src/test/java/org/openecomp/sdc/common/http/client/api/HttpClientFactoryTest.java
@@ -20,11 +20,11 @@
package org.openecomp.sdc.common.http.client.api;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.MockitoJUnitRunner;
import org.onap.sdc.security.SecurityUtil;
import org.openecomp.sdc.common.http.config.BasicAuthorization;
import org.openecomp.sdc.common.http.config.ClientCertificate;
@@ -36,15 +36,15 @@ import java.util.Map;
import static junit.framework.TestCase.assertNotNull;
-@ExtendWith(MockitoExtension.class)
-class HttpClientFactoryTest {
+@RunWith(MockitoJUnitRunner.class)
+public class HttpClientFactoryTest {
@Mock
- private HttpConnectionMngFactory httpConnectionMngFactory;
+ HttpConnectionMngFactory httpConnectionMngFactory;
@Test
- void validateNewClientCreationReturnsValidClient() {
- final HttpClient httpClient = new HttpClientFactory(httpConnectionMngFactory).createClient("Http", prepareTestClientConfigImmutable());
+ public void validateNewClientCreationReturnsValidClient() throws HttpExecuteException {
+ HttpClient httpClient = new HttpClientFactory(httpConnectionMngFactory).createClient("Http",prepareTestClientConfigImmutable());
assertNotNull(httpClient);
httpClient.close();
}
diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/http/client/api/HttpResponseTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/http/client/api/HttpResponseTest.java
index 85246a1b45..d96f071e3c 100644
--- a/common-app-api/src/test/java/org/openecomp/sdc/common/http/client/api/HttpResponseTest.java
+++ b/common-app-api/src/test/java/org/openecomp/sdc/common/http/client/api/HttpResponseTest.java
@@ -21,38 +21,38 @@
package org.openecomp.sdc.common.http.client.api;
import org.apache.http.HttpStatus;
-import org.junit.jupiter.api.Test;
+import org.junit.Test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
-class HttpResponseTest {
+public class HttpResponseTest {
@Test
- void validateNoDescriptionConstructor() {
+ public void validateNoDescriptionConstructor() {
final String testResponse = "test response";
HttpResponse<String> httpResponseTest = new HttpResponse<>(testResponse, HttpStatus.SC_OK);
- assertEquals(httpResponseTest.getStatusCode(), HttpStatus.SC_OK);
- assertEquals(httpResponseTest.getResponse(), testResponse);
- assertEquals(httpResponseTest.getDescription(), "");
+ assertEquals(httpResponseTest.getStatusCode(),HttpStatus.SC_OK);
+ assertEquals(httpResponseTest.getResponse(),testResponse);
+ assertEquals(httpResponseTest.getDescription(),"");
}
@Test
- void validateAllArgsConstructor() {
+ public void validateAllArgsConstructor() {
final String testResponse = "test response";
final String testDescription = "test description";
HttpResponse<String> httpResponseTest = new HttpResponse<>(testResponse, HttpStatus.SC_OK, testDescription);
- assertEquals(httpResponseTest.getStatusCode(), HttpStatus.SC_OK);
- assertEquals(httpResponseTest.getResponse(), testResponse);
- assertEquals(httpResponseTest.getDescription(), testDescription);
+ assertEquals(httpResponseTest.getStatusCode(),HttpStatus.SC_OK);
+ assertEquals(httpResponseTest.getResponse(),testResponse);
+ assertEquals(httpResponseTest.getDescription(),testDescription);
}
@Test
- void validateToStringConstructor() {
+ public void validateToStringConstructor() {
final String testResponse = "test response";
final String testDescription = "test description";
diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/util/StreamUtilsTests.java b/common-app-api/src/test/java/org/openecomp/sdc/common/util/StreamUtilsTests.java
new file mode 100644
index 0000000000..5ee8f42b6b
--- /dev/null
+++ b/common-app-api/src/test/java/org/openecomp/sdc/common/util/StreamUtilsTests.java
@@ -0,0 +1,142 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.sdc.common.util;
+
+import fj.data.Either;
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.junit.Assert.assertTrue;
+
+public class StreamUtilsTests {
+ @Test
+ public void testTakeWhilePredicateNotMet() {
+ List<Either<Integer, Boolean>> list = buildListWith10Integers();
+
+ assertEquals(10, StreamUtils.takeWhile(list.stream(), Either::isLeft).count());
+ }
+
+ @Test
+ public void testTakeWhilePredicateIsMet() {
+ List<Either<Integer, Boolean>> list = buildListWith10Integers();
+ addToBooleansToList(list);
+
+ final Stream<Either<Integer, Boolean>> takeWhileStream = StreamUtils.takeWhile(list.stream(), Either::isLeft);
+ assertEquals(0, takeWhileStream.filter(Either::isRight).count());
+ }
+
+ @Test
+ public <T> void testTakeErrorEvalOnlyOnce() {
+ List<Integer> bucket = new ArrayList<>();
+ // API
+ Function<Integer, Either<Integer, Boolean>> cons = num -> {
+ Either<Integer, Boolean> ret;
+ bucket.add(num);
+ if (num > 5) {
+ ret = Either.right(false);
+ } else {
+ ret = Either.left(num);
+ }
+ ;
+ return ret;
+ };
+
+ List<Integer> num1to10 = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+ Stream<Either<Integer, Boolean>> streamEithers = num1to10.stream().map(cons::apply);
+ List<Either<Integer, Boolean>> collect = StreamUtils.takeWhilePlusOneNoEval(streamEithers, Either::isLeft)
+ .collect(Collectors.toList());
+ assertTrue(bucket.size() <= 6);
+ assertTrue(collect.size() <= 6);
+ assertEquals(1, collect.stream().filter(Either::isRight).count());
+
+ }
+
+ @Test
+ public void testTakeWhilePlusOnePredicateNotMet() {
+ List<Either<Integer, Boolean>> list = buildListWith10Integers();
+
+ assertEquals(10, StreamUtils.takeWhilePlusOne(list.stream(), Either::isLeft).count());
+ }
+
+ @Test
+ public void testTakeWhilePlusOnePredicateIsMet() {
+ List<Either<Integer, Boolean>> list = buildListWith10Integers();
+ addToBooleansToList(list);
+
+ final Stream<Either<Integer, Boolean>> takeWhilePlusOneStream = StreamUtils.takeWhilePlusOne(list.stream(),
+ Either::isLeft);
+ assertEquals(1, takeWhilePlusOneStream.filter(Either::isRight).count());
+ }
+
+ private void addToBooleansToList(List<Either<Integer, Boolean>> list) {
+ list.add(Either.right(false));
+ list.add(Either.right(false));
+ }
+
+ private List<Either<Integer, Boolean>> buildListWith10Integers() {
+ List<Either<Integer, Boolean>> list = new ArrayList<>();
+ for (int i = 0; i < 10; i++) {
+ list.add(Either.left(i));
+ }
+ return list;
+ }
+
+ @Test
+ public void myTest() {
+ List<Integer> list = new ArrayList<>();
+ for (int i = 0; i < 10; i++) {
+ list.add(i);
+ }
+
+ List<Either<Integer, Boolean>> container = new ArrayList<>();
+ list.stream().map(e -> myBusinessLogic(e, container)).filter(Either::isRight).findAny();
+ // Actual Results are in container
+ assertEquals(6, container.size());
+
+ }
+
+ private Either<Integer, Boolean> myBusinessLogic(int e, List<Either<Integer, Boolean>> cobtainerList) {
+ Either<Integer, Boolean> eitherElement = similuteDBAccess(e);
+ // Keep The results in external List
+ cobtainerList.add(eitherElement);
+
+ return eitherElement;
+ }
+
+ private Either<Integer, Boolean> similuteDBAccess(int e) {
+ Either<Integer, Boolean> eitherElement;
+ if (e < 5) {
+ // DB Success
+ eitherElement = Either.left(e);
+ } else {
+ // DB Fail
+ eitherElement = Either.right(true);
+ }
+ return eitherElement;
+ }
+}