/**
* Builds an object with the specified value.
*
- * @param s
- * value to transport.
+ * @param n
+ * Name to transport
*/
- public AppTransport(String s) {
- this.name = s;
+ public AppTransport(String n) {
+ this.name = n;
}
public String getName() {
private static final long serialVersionUID = 1L;
// use transient per Sonar warning
- private transient final EcompUser ecompUser;
+ private final transient EcompUser ecompUser;
// This is the default Spring role-name prefix.
private static final String ROLEP = "ROLE_";
private String key;
private String name;
+ /**
+ * Builds an empty object.
+ */
+ public InstanceTransport() {
+ // no-arg constructor
+ }
+
+ /**
+ * Convenience constructor for minimal value set.
+ *
+ * @param key
+ * Key
+ * @param name
+ * Name
+ */
+ public InstanceTransport(String key, String name) {
+ this.key = key;
+ this.name = name;
+ }
+
public String getKey() {
return key;
}
private static final TrustManager[] UNQUESTIONING_TRUST_MANAGER = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
- return null;
+ return new java.security.cert.X509Certificate[0];
}
public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException {
import org.junit.Assert;
import org.junit.jupiter.api.Test;
+import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
import org.onap.portalsdk.core.restful.domain.EcompRole;
import org.onap.portalsdk.core.restful.domain.EcompUser;
import org.slf4j.Logger;
DashboardUserManager dum = new DashboardUserManager(true);
EcompUser user = createEcompUser(loginId);
dum.createUser(user);
- logger.debug("Created user {}", user);
+ logger.info("Created user {}", user);
+ try {
+ dum.createUser(user);
+ throw new Exception("Unexpected success");
+ } catch (PortalAPIException ex) {
+ logger.info("caught expected exception: {}", ex.toString());
+ }
Assert.assertFalse(dum.getUsers().isEmpty());
EcompUser fetched = dum.getUser(loginId);
Assert.assertEquals(fetched, user);
dum.updateUser(loginId, fetched);
EcompUser missing = dum.getUser("foo");
Assert.assertNull(missing);
+ EcompUser unk = createEcompUser("unknown");
+ try {
+ dum.updateUser("unk", unk);
+ } catch (PortalAPIException ex) {
+ logger.info("caught expected exception: {}", ex.toString());
+ }
}
}
*/
package org.oransc.ric.portal.dashboard.config;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
public SimpleKubernetesClient ciPltApi() throws IOException {
SimpleKubernetesClient mockClient = mock(SimpleKubernetesClient.class);
doAnswer(inv -> {
- logger.debug("listPods for plt");
- return pltPods;
- }).when(mockClient).listPods("ricplt");
+ String ns = inv.<String>getArgument(0);
+ logger.debug("listPods for namespace {}", ns);
+ if ("ricplt".equals(ns))
+ return pltPods;
+ else
+ throw new Exception("Fake server failure");
+ }).when(mockClient).listPods(any(String.class));
return mockClient;
}
@Configuration
@Profile("test")
-public class PortalApIMockConfiguration {
+public class PortalApiMockConfiguration {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
logger.debug("getUserId");
return "userId";
}).when(mockManager).validateEcompSso(any(HttpServletRequest.class));
- doAnswer(inv -> {
- logger.debug("getAppCredentials");
- return credentialsMap;
- }).when(mockManager).getAppCredentials();
return mockManager;
}
import java.lang.invoke.MethodHandles;
import java.net.URI;
+import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
Assertions.assertTrue(s.contains(nsPlt));
}
+ @Test
+ public void unknownClusterTest() {
+ final String nsPlt = "ricplt";
+ URI uri = buildUri(null, CaasIngressController.CONTROLLER_PATH, CaasIngressController.PODS_METHOD,
+ CaasIngressController.PP_CLUSTER, "cluster", CaasIngressController.PP_NAMESPACE, nsPlt);
+ logger.info("Invoking {}", uri);
+ String s = testRestTemplateStandardRole().getForObject(uri, String.class);
+ Assert.assertNull(s);
+ }
+
+ // Unknown namespace triggers a controller exception
+ @Test
+ public void bogusNsTest() {
+ final String ns = "unknown";
+ URI uri = buildUri(null, CaasIngressController.CONTROLLER_PATH, CaasIngressController.PODS_METHOD,
+ CaasIngressController.PP_CLUSTER, CaasIngressController.CLUSTER_PLT, CaasIngressController.PP_NAMESPACE,
+ ns);
+ logger.info("Invoking {}", uri);
+ String s = testRestTemplateStandardRole().getForObject(uri, String.class);
+ Assertions.assertFalse(s.isEmpty());
+ Assertions.assertTrue(s.contains("RIC Dashboard Error"));
+ }
+
}
import org.onap.portalsdk.core.restful.domain.EcompRole;
import org.onap.portalsdk.core.restful.domain.EcompUser;
import org.oransc.ric.portal.dashboard.DashboardConstants;
-import org.oransc.ric.portal.dashboard.config.PortalApIMockConfiguration;
+import org.oransc.ric.portal.dashboard.config.PortalApiMockConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
private HttpEntity<Object> getEntityWithHeaders(Object body) {
HttpHeaders headers = new HttpHeaders();
- headers.set(PortalApIMockConfiguration.PORTAL_USERNAME_HEADER_KEY,
- PortalApIMockConfiguration.PORTAL_USERNAME_HEADER_KEY);
- headers.set(PortalApIMockConfiguration.PORTAL_PASSWORD_HEADER_KEY,
- PortalApIMockConfiguration.PORTAL_PASSWORD_HEADER_KEY);
+ headers.set(PortalApiMockConfiguration.PORTAL_USERNAME_HEADER_KEY,
+ PortalApiMockConfiguration.PORTAL_USERNAME_HEADER_KEY);
+ headers.set(PortalApiMockConfiguration.PORTAL_PASSWORD_HEADER_KEY,
+ PortalApiMockConfiguration.PORTAL_PASSWORD_HEADER_KEY);
HttpEntity<Object> entity = new HttpEntity<>(body, headers);
return entity;
}
import java.lang.invoke.MethodHandles;
+import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.oransc.ric.portal.dashboard.util.HttpsURLConnectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
public class CaasIngressTest {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@Test
- public void test() throws Exception {
+ public void coverHttpsUtils() throws Exception {
HttpsURLConnectionUtils.turnOffSslChecking();
// Get IP address from REC deployment team for testing
final String podsUrl = "https://localhost:16443/api/v1/namespaces/ricaux/pods";
RestTemplate rt = new RestTemplate();
try {
- ResponseEntity<String> podsResponse = rt.getForEntity(podsUrl, String.class);
- logger.info(podsResponse.getBody());
+ rt.getForEntity(podsUrl, String.class);
+ Assert.assertTrue(false);
} catch (Exception ex) {
+ Assert.assertNotNull(ex);
logger.warn("Failed as expected");
}
HttpsURLConnectionUtils.turnOnSslChecking();
--- /dev/null
+/*-
+ * ========================LICENSE_START=================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2019 AT&T Intellectual Property
+ * %%
+ * 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.oransc.ric.portal.dashboard.model;
+
+import java.time.Instant;
+
+public abstract class AbstractModelTest {
+
+ // Values for properties
+ final boolean b1 = true;
+ final boolean b2 = false;
+ final byte[] by1 = { 0, 1, 2, 3 };
+ final Instant t1 = Instant.now().plusSeconds(1);
+ final Instant t2 = Instant.now().plusSeconds(2);
+ final Instant t3 = Instant.now().plusSeconds(3);
+ final Instant t4 = Instant.now().plusSeconds(4);
+ final Instant t5 = Instant.now().plusSeconds(5);
+ final Instant t6 = Instant.now().plusSeconds(6);
+ final Integer i1 = 1;
+ final Integer i2 = 2;
+ final Integer i3 = 3;
+ final Integer i4 = 4;
+ final Integer i5 = 5;
+ final Long l1 = 1L;
+ final Long l2 = 2L;
+ final Long l3 = 3L;
+ final Long l4 = 4L;
+ final String s1 = "string1";
+ final String s2 = "string2";
+ final String s3 = "string3";
+ final String s4 = "string4";
+ final String s5 = "string5";
+ final String s6 = "string6";
+ final String s7 = "string7";
+ final String s8 = "string8";
+ final String s9 = "string9";
+ final String s10 = "string10";
+ final String s11 = "string11";
+ final String s12 = "string12";
+ final String s13 = "string13";
+ final String u1 = "http://foo.com";
+ final String u2 = "http://bar.com";
+
+}
+++ /dev/null
-/*-
- * ========================LICENSE_START=================================
- * O-RAN-SC
- * %%
- * Copyright (C) 2019 AT&T Intellectual Property
- * %%
- * 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.oransc.ric.portal.dashboard.model;
-
-import java.lang.invoke.MethodHandles;
-
-import org.junit.Assert;
-import org.junit.jupiter.api.Test;
-import org.onap.portalsdk.core.restful.domain.EcompUser;
-import org.oransc.ric.portal.dashboard.DashboardUserManagerTest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class EcompUserDetailsTest {
-
- private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- @Test
- public void testEcompUserDetails() {
- EcompUser eu = DashboardUserManagerTest.createEcompUser("lgid");
- logger.info("EcompUser {}", eu);
- EcompUserDetails eud = new EcompUserDetails(eu);
- Assert.assertNotNull(eud.getAuthorities());
- Assert.assertNull(eud.getPassword());
- Assert.assertNotNull(eud.getUsername());
- Assert.assertTrue(eud.isAccountNonExpired());
- Assert.assertTrue(eud.isAccountNonLocked());
- }
-
-}
--- /dev/null
+/*-
+ * ========================LICENSE_START=================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2019 AT&T Intellectual Property
+ * %%
+ * 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.oransc.ric.portal.dashboard.model;
+
+import java.lang.invoke.MethodHandles;
+
+import org.junit.Assert;
+import org.junit.jupiter.api.Test;
+import org.onap.portalsdk.core.restful.domain.EcompUser;
+import org.oransc.ric.e2mgr.client.model.GetNodebResponse;
+import org.oransc.ric.e2mgr.client.model.NodebIdentity;
+import org.oransc.ric.portal.dashboard.DashboardUserManagerTest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ModelTest extends AbstractModelTest {
+
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ private void checkAppTransport(AppTransport m) {
+ Assert.assertEquals(s1, m.getName());
+ Assert.assertEquals(s2, m.getVersion());
+ }
+
+ @Test
+ public void testAppTransport() {
+ AppTransport m = new AppTransport(s1);
+ m = new AppTransport();
+ m.setName(s1);
+ m.setVersion(s2);
+ checkAppTransport(m);
+ logger.info(m.toString());
+ }
+
+ @Test
+ public void testEcompUserDetails() {
+ EcompUser eu = DashboardUserManagerTest.createEcompUser("lgid");
+ logger.info("EcompUser {}", eu);
+ EcompUserDetails eud = new EcompUserDetails(eu);
+ Assert.assertNotNull(eud.getAuthorities());
+ Assert.assertNull(eud.getPassword());
+ Assert.assertNotNull(eud.getUsername());
+ Assert.assertTrue(eud.isAccountNonExpired());
+ Assert.assertTrue(eud.isAccountNonLocked());
+ }
+
+ private void checkErrorTransport(ErrorTransport m) {
+ Assert.assertEquals(s1, m.getError());
+ Assert.assertEquals(s2, m.getMessage());
+ Assert.assertEquals(s3, m.getPath());
+ Assert.assertEquals(i1, m.getStatus());
+ Assert.assertEquals(t1, m.getTimestamp());
+ }
+
+ @Test
+ public void testErrorTransport() {
+ ErrorTransport m = new ErrorTransport(i1, s1);
+ m = new ErrorTransport(i1, new Exception());
+ m = new ErrorTransport(i1, s1, s2, s3);
+ m = new ErrorTransport();
+ m.setError(s1);
+ m.setMessage(s2);
+ m.setPath(s3);
+ m.setStatus(i1);
+ m.setTimestamp(t1);
+ checkErrorTransport(m);
+ logger.info(m.toString());
+ }
+
+ private void checkInstanceTransport(InstanceTransport m) {
+ Assert.assertEquals(s1, m.getKey());
+ Assert.assertEquals(s2, m.getName());
+ }
+
+ @Test
+ public void testInstanceTransport() {
+ InstanceTransport m = new InstanceTransport(s1, s1);
+ m = new InstanceTransport();
+ m.setKey(s1);
+ m.setName(s2);
+ checkInstanceTransport(m);
+ logger.info(m.toString());
+ }
+
+ @Test
+ public void testRanDetailsTransport() {
+ RanDetailsTransport m = new RanDetailsTransport();
+ NodebIdentity nodebIdentity = new NodebIdentity();
+ GetNodebResponse nodebResponse = new GetNodebResponse();
+ m = new RanDetailsTransport(nodebIdentity, nodebResponse);
+ Assert.assertEquals(m.getNodebIdentity(), nodebIdentity);
+ Assert.assertEquals(m.getNodebStatus(), nodebResponse);
+ }
+
+ private void checkSuccessTransport(SuccessTransport m) {
+ Assert.assertEquals(s1, m.getData());
+ Assert.assertEquals(1, m.getStatus());
+ }
+
+ @Test
+ public void testSuccessTransport() {
+ SuccessTransport m = new SuccessTransport(1, s1);
+ m = new SuccessTransport();
+ m.setData(s1);
+ m.setStatus(1);
+ checkSuccessTransport(m);
+ logger.info(m.toString());
+ }
+
+}