diff options
author | sstoykov <stela.stoykova@amdocs.com> | 2018-11-26 15:45:47 -0500 |
---|---|---|
committer | sstoykov <stela.stoykova@amdocs.com> | 2018-11-27 15:24:24 -0500 |
commit | 5e4b48acc875f88e2958b4469cb889222ca2f11c (patch) | |
tree | e432b2932ebc442cd8c50b0b76e41cb01f307405 /sparkybe-onap-service/src/test/java/org/onap | |
parent | 14f155e7a8a93b499b4f4eed801281dc92faca14 (diff) |
Removed edit attribute code
Removed obsolete code related to the edit attributes feature from
sparky-be.
Issue-ID: AAI-1956
Change-Id: I25754ec5440ce199ca5678b2074a1f090dde46ab
Signed-off-by: sstoykov <stela.stoykova@amdocs.com>
Diffstat (limited to 'sparkybe-onap-service/src/test/java/org/onap')
5 files changed, 0 insertions, 628 deletions
diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/AttributeUpdaterTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/AttributeUpdaterTest.java deleted file mode 100644 index a5f7049..0000000 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/AttributeUpdaterTest.java +++ /dev/null @@ -1,166 +0,0 @@ -/** - * ============LICENSE_START=================================================== - * SPARKY (AAI UI service) - * ============================================================================ - * Copyright © 2017 AT&T Intellectual Property. - * Copyright © 2017 Amdocs - * 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===================================================== - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. - */ - -package org.onap.aai.sparky.editattributes; - -import static org.junit.Assert.assertEquals; - -import java.util.HashMap; -import java.util.Map; - -import javax.ws.rs.core.Response.Status; - -import org.eclipse.persistence.dynamic.DynamicType; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.onap.aai.restclient.client.OperationResult; -import org.onap.aai.setup.SchemaVersion; -import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor; -import org.onap.aai.sparky.config.oxm.OxmEntityLookup; -import org.onap.aai.sparky.config.oxm.OxmModelLoader; -import org.onap.aai.sparky.dal.ActiveInventoryAdapter; -import org.onap.aai.sparky.editattributes.AttributeUpdater.AaiEditObject; - - - -/** - * The Class AttributeUpdaterTest. - */ -public class AttributeUpdaterTest { - - private ActiveInventoryAdapter aaiAdapter; - - /** - * Sets the up. - * - * @throws Exception the exception - */ - @Before - public void setUp() throws Exception { - - aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class); - } - - /** - * @throws Exception - */ - - @Test - public void testUpdateObjectAttribute() throws Exception { - - OxmEntityDescriptor desc = new OxmEntityDescriptor(); - desc.addPrimaryKeyName("hostname"); - desc.setEntityName("pserver"); - OxmEntityLookup entityLookup = new OxmEntityLookup(); - entityLookup.addEntityDescriptor("pserver", desc); - - AttributeUpdater updater = - new AttributeUpdater(new OxmModelLoader("v11", null, null), entityLookup, aaiAdapter,"aai"); - Map<String, Object> attributes = new HashMap<>(); - attributes.put("prov-status", "PREPROV"); - attributes.put("in-maint", "true"); - OperationResult result = updater.updateObjectAttribute( - "cloud-infrastructure/pservers/pserver/something", attributes, "someid"); - assertEquals(Status.FORBIDDEN.getStatusCode(), result.getResultCode()); - } - - - // This needs the OXM file in place to work. - /** - * Test get edit object from uri. - * - * @throws Exception the exception - */ - @Test(expected = NullPointerException.class) - public void testGetEditObjectFromUri() throws Exception { - String version = "v11"; - OxmModelLoader loader = new OxmModelLoader(version, null, null); - - - OxmEntityDescriptor desc = new OxmEntityDescriptor(); - desc.addPrimaryKeyName("hostname"); - desc.setEntityName("pserver"); - - OxmEntityLookup entityLookup = new OxmEntityLookup(); - entityLookup.addEntityDescriptor("pserver", desc); - - - // DynamicType mockType = Mockito.mock(DynamicType.class); - // Class<? extends DynamicEntity> mockDynamicEntity = Mockito.mock(DynamicEntity.class); - - // Mockito.when(mockType.getJavaClass()).thenReturn(mockDynamicEntity); - - - - HashMap<String, DynamicType> typeLookup = new HashMap<String, DynamicType>(); - // typeLookup.put("pserver", mockType); - - entityLookup.setEntityTypeLookup(typeLookup); - - - AttributeUpdater updater = - new AttributeUpdater(new OxmModelLoader(version, null, null), entityLookup, aaiAdapter,"aai"); - AaiEditObject result = updater.getEditObjectFromUri(null); - assertEquals("Pserver", result.getObjectType()); - assertEquals("pserver", result.getRootElement()); - assertEquals("hostname", result.getKeyName()); - assertEquals("mtznjtax101", result.getKeyValue()); - } - - /** - * Test get relative uri. - * - * @throws Exception the exception - */ - - @Test - public void testGetRelativeUri() throws Exception { - - OxmEntityDescriptor desc = new OxmEntityDescriptor(); - desc.addPrimaryKeyName("hostname"); - desc.setEntityName("pserver"); - - OxmEntityLookup entityLookup = new OxmEntityLookup(); - entityLookup.addEntityDescriptor("pserver", desc); - - AttributeUpdater updater = new AttributeUpdater(new OxmModelLoader("v11",null,null), entityLookup, aaiAdapter,"aai"); - // Test entity uri without "/aai/version/" - String result = updater.getRelativeUri("cloud-infrastructure/pservers/pserver/mtznjtax101"); - assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result); - result = updater.getRelativeUri("/aai/v8/cloud-infrastructure/pservers/pserver/mtznjtax101"); - assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result); - - result = updater.getRelativeUri("/v8/cloud-infrastructure/pservers/pserver/mtznjtax101"); - assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result); - - result = updater.getRelativeUri("aai/v88/cloud-infrastructure/pservers/pserver/mtznjtax101"); - assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result); - - result = updater.getRelativeUri("/cloud-infrastructure/pservers/pserver/mtznjtax101"); - assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result); - } - -}
\ No newline at end of file diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/EditAttributesTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/EditAttributesTest.java deleted file mode 100644 index 4e7e80a..0000000 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/EditAttributesTest.java +++ /dev/null @@ -1,171 +0,0 @@ -/** - * ============LICENSE_START=================================================== - * SPARKY (AAI UI service) - * ============================================================================ - * Copyright © 2017 AT&T Intellectual Property. - * Copyright © 2017 Amdocs - * 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===================================================== - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. - */ - -package org.onap.aai.sparky.editattributes; - -import java.io.IOException; -import java.io.InputStream; - -import javax.servlet.ReadListener; -import javax.servlet.ServletInputStream; - -import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.BeforeClass; - - -/** - * The Class EditAttributesTest. - */ -public class EditAttributesTest { - String sampleJsonRequest = - "{ \"entity-uri\" : \"some/uri/value/here\", \"entity-type\" : \"complex\"," - + " \"attributes\" : { \"prov-status\" : \"PREPROV\", \"inMaint\" : \"true\"," - + " \"isClosedLoop\" : \"false\" }}"; - - /** - * Sets the up before class. - * - * @throws Exception the exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception {} - - /** - * Sets the up. - * - * @throws Exception the exception - */ - @Before - public void setUp() throws Exception {} - - - /** - * Test analyze edit request body. - */ - /* - @Test - public void testAnalyzeEditRequestBody() { - AttributeEditProcessor aes = new AttributeEditProcessor(); - EditRequest request = aes.analyzeEditRequestBody(sampleJsonRequest); - System.out.println("JSON Body : " + sampleJsonRequest); - assertNotNull(request); - assertEquals("URI should match", "some/uri/value/here", request.getEntityUri()); - assertEquals("Entity Type should match", "complex", request.getEntityType()); - assertEquals("Attribute ProvStatus should match", "PREPROV", - request.getAttributes().get("prov-status")); - assertEquals("Attribute inMaint should be true", "true", - request.getAttributes().get("inMaint")); - assertEquals("Attribute isClosedLoop should be false", "false", - request.getAttributes().get("isClosedLoop")); - - } - */ - - - /** - * Test edit request. - * - * @throws IOException Signals that an I/O exception has occurred. - * @throws ServletException the servlet exception - * @throws JSONException the JSON exception - */ - /* - @Test - public void testEditRequest() throws IOException, ServletException, JSONException { - HttpServletRequest mockRequest = mock(HttpServletRequest.class); - HttpServletResponse mockResponse = mock(HttpServletResponse.class); - ServletOutputStream mockOutput = mock(ServletOutputStream.class); - ServletInputStream mockInput = new MockServletInputStream(sampleJsonRequest); - - when(mockRequest.getRequestURI()).thenReturn("editAttributes"); - when(mockResponse.getOutputStream()).thenReturn(mockOutput); - - when(mockRequest.getInputStream()).thenReturn(mockInput); - - Principal princip = new UserPrincipal("ds1150"); - - when(mockRequest.getUserPrincipal()).thenReturn(princip); - - PrintWriter writer = new PrintWriter("editServletTest.txt"); - when(mockResponse.getWriter()).thenReturn(writer); - AttributeEditProcessor aes = new AttributeEditProcessor(); - aes.doPost(mockRequest, mockResponse); - JSONObject result = null; - try { - writer.close(); - result = new JSONObject(FileUtils.readFileToString(new File("editServletTest.txt"), "UTF-8")); - } catch (JSONException ex) { - // Nothing to catch - } - assertNotNull(result); - // assertEquals("Attributes updated successfully (just need PATCH !!!)", result.get("result")); - } - */ - - - - /** - * The Class MockServletInputStream. - */ - class MockServletInputStream extends ServletInputStream { - InputStream inputStream; - - /** - * Instantiates a new mock servlet input stream. - * - * @param string the string - */ - MockServletInputStream(String string) { - this.inputStream = IOUtils.toInputStream(string); - } - - /* (non-Javadoc) - * @see java.io.InputStream#read() - */ - @Override - public int read() throws IOException { - return inputStream.read(); - } - - @Override - public boolean isFinished() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isReady() { - // TODO Auto-generated method stub - return false; - } - - @Override - public void setReadListener(ReadListener readListener) { - // TODO Auto-generated method stub - - } - } -} diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/TestUserAuthorizationReader.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/TestUserAuthorizationReader.java deleted file mode 100644 index 4f99b6d..0000000 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/TestUserAuthorizationReader.java +++ /dev/null @@ -1,113 +0,0 @@ -/** - * ============LICENSE_START=================================================== - * SPARKY (AAI UI service) - * ============================================================================ - * Copyright © 2017 AT&T Intellectual Property. - * Copyright © 2017 Amdocs - * 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===================================================== - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. - */ - -package org.onap.aai.sparky.editattributes; - -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertThat; - -import java.io.File; -import java.nio.file.Paths; -import java.util.List; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.aai.sparky.editattributes.UserAuthorizationReader; - -/** - * The Class TestUserAuthorizationReader. - */ -public class TestUserAuthorizationReader { - - private static File userAuthFile; - private static File userAuthFileEmpty; - - /** - * Sets the up before class. - * - * @throws Exception the exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - userAuthFile = Paths.get(TestData.USER_AUTH_FILE.getFilename()).toFile(); - userAuthFileEmpty = Paths.get(TestData.USER_AUTH_FILE_EMPTY.getFilename()).toFile(); - } - - /** - * The Enum TestData. - */ - enum TestData { - // @formatter:off - USER_AUTH_FILE( - "src/test/resources/user-auth-reader/authorized-users.config"), USER_AUTH_FILE_EMPTY( - "src/test/resources/user-auth-reader/authorized-users-empty.config"); - - private String filename; - - /** - * Instantiates a new test data. - * - * @param filename the filename - */ - TestData(String filename) { - this.filename = filename; - } - - public String getFilename() { - return this.filename; - } - // @formatter:on - } - - /** - * Test get users. - * - * @throws Exception the exception - */ - @Test - public void testGetUsers() throws Exception { - UserAuthorizationReader userAuthorizationReader = new UserAuthorizationReader(userAuthFile); - - // Method under test - List<String> userList = userAuthorizationReader.getUsers(); - - assertThat(userList, containsInAnyOrder("user1", "user2 user3", "user4")); - } - - /** - * Test get users passing empty config. - * - * @throws Exception the exception - */ - @Test - public void testGetUsersPassingEmptyConfig() throws Exception { - UserAuthorizationReader userConfigReader = new UserAuthorizationReader(userAuthFileEmpty); - - List<String> userList = userConfigReader.getUsers(); - - assertThat(userList, empty()); - } -} diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/TestUserValidator.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/TestUserValidator.java deleted file mode 100644 index df41a5e..0000000 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/TestUserValidator.java +++ /dev/null @@ -1,135 +0,0 @@ -/** - * ============LICENSE_START=================================================== - * SPARKY (AAI UI service) - * ============================================================================ - * Copyright © 2017 AT&T Intellectual Property. - * Copyright © 2017 Amdocs - * 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===================================================== - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. - */ - -package org.onap.aai.sparky.editattributes; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.when; - -import java.io.File; -import java.nio.file.Paths; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.aai.sparky.editattributes.UserAuthorizationReader; -import org.onap.aai.sparky.editattributes.UserValidator; - -/** - * The Class TestUserValidator. - */ -@RunWith(MockitoJUnitRunner.class) -public class TestUserValidator { - - @Mock - private UserAuthorizationReader userAuthorizationReader; - - @InjectMocks - private UserValidator userValidator; - - private static File userAuthFile; - private static File missingUserAuthFile; - - /** - * Sets the up before class. - * - * @throws Exception the exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - userAuthFile = Paths.get(TestData.USER_AUTH_FILE.getFilename()).toFile(); - missingUserAuthFile = Paths.get(TestData.MISSING_USER_AUTH_FILE.getFilename()).toFile(); - } - - /** - * The Enum TestData. - */ - enum TestData { - // @formatter:off - USER_AUTH_FILE( - "src/test/resources/user-validator/authorized-users.config"), MISSING_USER_AUTH_FILE( - "src/test/resources/user-validator/missing.config"); - - private String filename; - - /** - * Instantiates a new test data. - * - * @param filename the filename - */ - TestData(String filename) { - this.filename = filename; - } - - public String getFilename() { - return this.filename; - } - // @formatter:on - } - - /** - * Test is authorized user. - * - * @throws Exception the exception - */ - @Test - public void testIsAuthorizedUser() throws Exception { - when(userAuthorizationReader.getUsers()).thenCallRealMethod(); - when(userAuthorizationReader.getUserAuthorizationFile()).thenReturn(userAuthFile); - - boolean isAuthUser = userValidator.isAuthorizedUser("user1"); - assertThat(isAuthUser, is(true)); - - boolean isAuthUser2 = userValidator.isAuthorizedUser("user2"); - assertThat(isAuthUser2, is(false)); - - boolean isAuthUser3 = userValidator.isAuthorizedUser("user3"); - assertThat(isAuthUser3, is(false)); - - boolean isAuthUser4 = userValidator.isAuthorizedUser("not-in-file"); - assertThat(isAuthUser4, is(false)); - - boolean isAuthUser5 = userValidator.isAuthorizedUser("user4"); - assertThat(isAuthUser5, is(true)); - } - - /** - * Test not authorized if file not present. - * - * @throws Exception the exception - */ - @Test - public void testNotAuthorizedIfFileNotPresent() throws Exception { - when(userAuthorizationReader.getUsers()).thenCallRealMethod(); - when(userAuthorizationReader.getUserAuthorizationFile()).thenReturn(missingUserAuthFile); - - boolean isAuthUser = userValidator.isAuthorizedUser("user1"); - assertThat(isAuthUser, is(false)); - } -} diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/entity/EditRequestTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/entity/EditRequestTest.java deleted file mode 100644 index 5f87a27..0000000 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/entity/EditRequestTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.onap.aai.sparky.editattributes.entity; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.HashMap; - -import org.junit.Before; -import org.junit.Test; -import org.onap.aai.sparky.viewandinspect.EntityTypeAggregation; -import org.onap.aai.sparky.viewandinspect.entity.GraphMeta; - -import com.fasterxml.jackson.databind.node.JsonNodeFactory; - -public class EditRequestTest { - - private EditRequest editAttribute; - private HashMap<String,Object> attributes; - - - - @Before - public void init() throws Exception { - - editAttribute = new EditRequest(); - attributes = new HashMap<String,Object>(); - - } - - - @Test - public void updateValues() { - - editAttribute.setEntityUri(""); - assertNotNull(editAttribute.getEntityUri()); - editAttribute.setEntityType(""); - assertNotNull(editAttribute.getEntityType()); - editAttribute.setAttributes(attributes); - assertNotNull(editAttribute.getAttributes()); - } - -} |