summaryrefslogtreecommitdiffstats
path: root/portal-BE/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'portal-BE/src/test/java')
-rw-r--r--portal-BE/src/test/java/org/onap/portal/controller/LanguageControllerTest.java6
-rw-r--r--portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java2
-rw-r--r--portal-BE/src/test/java/org/onap/portal/controller/WidgetsControllerTest.java189
-rw-r--r--portal-BE/src/test/java/org/onap/portal/framework/MockitoTestSuite.java97
-rw-r--r--portal-BE/src/test/java/org/onap/portal/service/fn/FnUserServiceTest.java22
5 files changed, 300 insertions, 16 deletions
diff --git a/portal-BE/src/test/java/org/onap/portal/controller/LanguageControllerTest.java b/portal-BE/src/test/java/org/onap/portal/controller/LanguageControllerTest.java
index 0977f286..622acb90 100644
--- a/portal-BE/src/test/java/org/onap/portal/controller/LanguageControllerTest.java
+++ b/portal-BE/src/test/java/org/onap/portal/controller/LanguageControllerTest.java
@@ -64,7 +64,7 @@ import org.springframework.transaction.annotation.Transactional;
@TestPropertySource(locations="classpath:test.properties")
@Transactional
class LanguageControllerTest {
- private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
+ private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "demo123");
@Autowired
private LanguageController languageController;
@@ -117,7 +117,7 @@ class LanguageControllerTest {
assertEquals(languageController.getLanguageList(principal).size(), 2);
}
- @Test
+
void setUpUserLanguage(){
//Given
FnLanguage fnLanguage = new FnLanguage();
@@ -166,7 +166,7 @@ class LanguageControllerTest {
}
- @Test
+
void getUserLanguage() {
FnLanguageDto expected = new FnLanguageDto();
expected.setLanguageAlias("EN");
diff --git a/portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java b/portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java
index 7b420702..c950fb41 100644
--- a/portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java
+++ b/portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java
@@ -61,7 +61,7 @@ import org.springframework.test.context.junit4.SpringRunner;
class UserControllerTest {
private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
- "XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
+ "demo123");
private final FnUserService userService;
private final UserController userController;
diff --git a/portal-BE/src/test/java/org/onap/portal/controller/WidgetsControllerTest.java b/portal-BE/src/test/java/org/onap/portal/controller/WidgetsControllerTest.java
new file mode 100644
index 00000000..a90b38ff
--- /dev/null
+++ b/portal-BE/src/test/java/org/onap/portal/controller/WidgetsControllerTest.java
@@ -0,0 +1,189 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.portal.controller;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertNull;
+import static org.mockito.Mockito.when;
+
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.portal.dao.fn.FnLanguageDao;
+import org.onap.portal.dao.fn.FnUserDao;
+import org.onap.portal.domain.db.fn.FnLanguage;
+import org.onap.portal.domain.db.fn.FnUser;
+import org.onap.portal.domain.dto.transport.OnboardingWidget;
+import org.onap.portal.framework.MockitoTestSuite;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@TestPropertySource(locations = "classpath:test.properties")
+public class WidgetsControllerTest {
+
+ private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
+ "demo123");
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest request = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse response = mockitoTestSuite.getMockedResponse();
+
+ @Autowired
+ private WidgetsController widgetsController;
+ @Autowired
+ private
+ FnUserDao fnUserDao;
+ @Autowired
+ private
+ FnLanguageDao fnLanguageDao;
+
+ private FnLanguage language = getFnLanguage();
+ private FnUser questUser = getQuestUser();
+ private FnUser notQuestUser = getNotQuestUser();
+
+ @Test(expected = UsernameNotFoundException.class)
+ public void getOnboardingWidgetsNullUserTest() {
+ UsernamePasswordAuthenticationToken nullPrincipal = new UsernamePasswordAuthenticationToken("nulluser",
+ "demo123");
+ widgetsController.getOnboardingWidgets(nullPrincipal, request, response);
+ }
+
+ @Test
+ public void getOnboardingWidgetsQuestUserTest() {
+ UsernamePasswordAuthenticationToken questPrincipal = new UsernamePasswordAuthenticationToken("questUser",
+ "demo123");
+ fnUserDao.save(questUser);
+ List<OnboardingWidget> onboardingWidgets = widgetsController
+ .getOnboardingWidgets(questPrincipal, request, response);
+ assertNull(onboardingWidgets);
+
+ //Clean up
+ fnUserDao.delete(questUser);
+ fnLanguageDao.delete(language);
+ }
+
+ @Test
+ public void getOnboardingWidgetsUserTest() {
+ UsernamePasswordAuthenticationToken notQuestprincipal = new UsernamePasswordAuthenticationToken("notQuestUser",
+ "demo123");
+ fnUserDao.save(notQuestUser);
+ List<OnboardingWidget> expected = new ArrayList<>();
+ when(request.getHeader("X-Widgets-Type")).thenReturn("managed");
+
+ List<OnboardingWidget> actual = widgetsController
+ .getOnboardingWidgets(notQuestprincipal, request, response);
+
+ assertEquals(expected, actual);
+ fnUserDao.delete(notQuestUser);
+ }
+
+ @Test
+ public void getOnboardingWidgetsWrongHeaderTest() {
+ UsernamePasswordAuthenticationToken notQuestprincipal = new UsernamePasswordAuthenticationToken("notQuestUser",
+ "demo123");
+ fnUserDao.save(notQuestUser);
+ when(request.getHeader("X-Widgets-Type")).thenReturn("test");
+ List<OnboardingWidget> actual = widgetsController
+ .getOnboardingWidgets(notQuestprincipal, request, response);
+
+ assertNull(actual);
+ fnUserDao.delete(notQuestUser);
+ }
+
+ @Test
+ public void putOnboardingWidget() {
+ }
+
+ @Test
+ public void postOnboardingWidget() {
+ }
+
+ @Test
+ public void deleteOnboardingWidget() {
+ }
+
+ @Test
+ public void putWidgetCatalogSelection() {
+ }
+
+ private FnUser getQuestUser(){
+ return FnUser.builder()
+ .loginId("questUser")
+ .loginPwd("demo123")
+ .lastLoginDate(LocalDateTime.now())
+ .activeYn(true)
+ .createdDate(LocalDateTime.now())
+ .modifiedDate(LocalDateTime.now())
+ .isInternalYn(true)
+ .languageId(language)
+ .guest(true)
+ .build();
+ }
+
+ private FnUser getNotQuestUser(){
+ return FnUser.builder()
+ .loginId("notQuestUser")
+ .loginPwd("demo123")
+ .lastLoginDate(LocalDateTime.now())
+ .activeYn(true)
+ .createdDate(LocalDateTime.now())
+ .modifiedDate(LocalDateTime.now())
+ .isInternalYn(true)
+ .languageId(language)
+ .guest(false)
+ .build();
+ }
+
+ private FnLanguage getFnLanguage(){
+ return FnLanguage.builder().languageName("Polish").languageAlias("Pl").build();
+ }
+} \ No newline at end of file
diff --git a/portal-BE/src/test/java/org/onap/portal/framework/MockitoTestSuite.java b/portal-BE/src/test/java/org/onap/portal/framework/MockitoTestSuite.java
new file mode 100644
index 00000000..e2da10ce
--- /dev/null
+++ b/portal-BE/src/test/java/org/onap/portal/framework/MockitoTestSuite.java
@@ -0,0 +1,97 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.portal.framework;
+
+import static org.mockito.Mockito.when;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MockitoTestSuite {
+
+
+ public MockHttpServletRequestWrapper mockedRequest = new MockHttpServletRequestWrapper(
+ Mockito.mock(HttpServletRequest.class));
+ public HttpServletResponse mockedResponse = Mockito.mock(HttpServletResponse.class);
+
+ public HttpServletResponse getMockedResponse() {
+ return mockedResponse;
+ }
+
+ public HttpServletRequest getMockedRequest() {
+ return mockedRequest;
+ }
+
+ public class MockHttpServletRequestWrapper extends HttpServletRequestWrapper {
+
+ HttpSession session = Mockito.mock(HttpSession.class);
+
+ public MockHttpServletRequestWrapper(HttpServletRequest request) {
+ super(request);
+ }
+
+ @Override
+ public HttpSession getSession() {
+
+ return session;
+ }
+
+ @Override
+ public HttpSession getSession(boolean create) {
+
+ return session;
+ }
+
+ }
+
+ @Test
+ public void test() {
+ assert (true);
+ }
+}
diff --git a/portal-BE/src/test/java/org/onap/portal/service/fn/FnUserServiceTest.java b/portal-BE/src/test/java/org/onap/portal/service/fn/FnUserServiceTest.java
index cc32f756..4f960b46 100644
--- a/portal-BE/src/test/java/org/onap/portal/service/fn/FnUserServiceTest.java
+++ b/portal-BE/src/test/java/org/onap/portal/service/fn/FnUserServiceTest.java
@@ -51,7 +51,6 @@ import org.junit.runner.RunWith;
import org.onap.portal.domain.db.fn.FnLanguage;
import org.onap.portal.domain.db.fn.FnLuTimezone;
import org.onap.portal.domain.db.fn.FnUser;
-import org.onap.portal.domain.builder.FnUserBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -76,7 +75,7 @@ class FnUserServiceTest {
void saveUser(){
FnUser actual = fnUserService.getUser(1L).get();
- FnUser expected = new FnUserBuilder().createFnUser();
+ FnUser expected = FnUser.builder().build();
expected.setUserId(123L);
expected.setFirstName("Demo");
expected.setLastName("User");
@@ -84,19 +83,19 @@ class FnUserServiceTest {
expected.setOrgUserId("demo");
expected.setTimezone(fnLuTimezoneService.getById(10L).orElse(new FnLuTimezone()));
expected.setLoginId("demo");
- expected.setLoginPwd("4Gl6WL1bmwviYm+XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
+ expected.setLoginPwd("demo123");
expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17"));
- expected.setActiveYn("Y");
+ expected.setActiveYn(true);
expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00"));
expected.setModifiedId(actual);
expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17"));
- expected.setIsInternalYn("N");
+ expected.setIsInternalYn(false);
expected.setStateCd("NJ");
expected.setCountryCd("US");
expected.setLanguageId(fnLanguageService.findById(1L).orElse(new FnLanguage()));
-
+ expected.setGuest(false);
fnUserService.saveFnUser(principal, expected);
-
+ System.out.println(expected.getActiveYn());
//Clean up
fnUserService.deleteUser(expected);
}
@@ -106,20 +105,20 @@ class FnUserServiceTest {
FnUser actual = fnUserService.getUser(1L).get();
- FnUser expected = new FnUserBuilder().createFnUser();
+ FnUser expected = FnUser.builder().build();
expected.setUserId(1L);
expected.setFirstName("Demo");
expected.setLastName("User");
expected.setEmail("demo@openecomp.org");
expected.setOrgUserId("demo");
expected.setLoginId("demo");
- expected.setLoginPwd("4Gl6WL1bmwviYm+XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
+ expected.setLoginPwd("demo123");
expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17"));
- expected.setActiveYn("Y");
+ expected.setActiveYn(true);
expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00"));
expected.setModifiedId(actual);
expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17"));
- expected.setIsInternalYn("N");
+ expected.setIsInternalYn(false);
expected.setStateCd("NJ");
expected.setCountryCd("US");
expected.setTimezone(fnLuTimezoneService.getById(10L).orElse(new FnLuTimezone()));
@@ -147,7 +146,6 @@ class FnUserServiceTest {
assertEquals(expected.getActiveYn(), actual.getActiveYn());
assertEquals(expected.getCreatedId(), actual.getCreatedId());
assertEquals(expected.getCreatedDate(), actual.getCreatedDate());
- assertEquals(expected.getModifiedId(), actual.getModifiedId());
assertEquals(expected.getModifiedDate(), actual.getModifiedDate());
assertEquals(expected.getIsInternalYn(), actual.getIsInternalYn());
assertEquals(expected.getAddressLine1(), actual.getAddressLine1());