Merge "Make CategoryParameter.getOptions() unmodifiable"
authorIttay Stern <ittay.stern@att.com>
Wed, 12 Dec 2018 11:22:20 +0000 (11:22 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 12 Dec 2018 11:22:20 +0000 (11:22 +0000)
1  2 
vid-app-common/src/test/java/org/onap/vid/services/CategoryParameterServiceImplTest.java

   */
  package org.onap.vid.services;
  
 -import static org.mockito.Matchers.anyObject;
 -import static org.mockito.Matchers.anyString;
 -import static org.mockito.Mockito.doReturn;
 -import static org.mockito.Mockito.reset;
 -import static org.mockito.Mockito.times;
 -import static org.mockito.Mockito.verify;
 -import static org.mockito.MockitoAnnotations.initMocks;
 -
 -import java.util.ArrayList;
 -import java.util.Collections;
 -import java.util.List;
 -import javax.ws.rs.ForbiddenException;
  import org.mockito.InjectMocks;
  import org.mockito.Mock;
  import org.onap.portalsdk.core.service.DataAccessService;
@@@ -38,16 -50,6 +38,16 @@@ import org.testng.annotations.BeforeMet
  import org.testng.annotations.BeforeSuite;
  import org.testng.annotations.Test;
  
 +import javax.ws.rs.ForbiddenException;
 +import java.util.ArrayList;
 +import java.util.Collections;
 +import java.util.List;
 +
 +import static org.mockito.ArgumentMatchers.any;
 +import static org.mockito.ArgumentMatchers.anyString;
 +import static org.mockito.Mockito.*;
 +import static org.mockito.MockitoAnnotations.initMocks;
 +
  public class CategoryParameterServiceImplTest {
  
      private static final String CATEGORY_NAME = "SAMPLE_CATEGORY_NAME";
@@@ -87,7 -89,7 +87,7 @@@
  
          Assert.assertTrue(result.getErrors().isEmpty());;
          verify(dataAccessService, times(1))
 -            .saveDomainObject(anyObject(), anyObject());
 +            .saveDomainObject(any(), any());
      }
  
      @Test
@@@ -95,7 -97,8 +95,8 @@@
          AddCategoryOptionsRequest optionsRequest = new AddCategoryOptionsRequest();
          optionsRequest.options.add(OPTION_NAME);
          CategoryParameter categoryParameter = createCategoryParameter(CATEGORY_NAME, true);
-         categoryParameter.getOptions().add(new CategoryParameterOption(APP_ID_VID, OPTION_NAME, categoryParameter));
+         CategoryParameter anotherCategoryParameter = createCategoryParameter(CATEGORY_NAME, true);
+         categoryParameter.addOption(new CategoryParameterOption(APP_ID_VID, OPTION_NAME, anotherCategoryParameter));
          List<CategoryParameter> aList = createCategoryParametersList(categoryParameter);
  
          String expectedError = String.format(CategoryParameterServiceImpl.OPTION_ALREADY_EXIST_FOR_CATEGORY
      @Test
      public void deleteCategoryOption_happyPath() {
          CategoryParameter categoryParameter = createCategoryParameter(CATEGORY_NAME, true);
+         CategoryParameter anotherCategoryParameter = createCategoryParameter(CATEGORY_NAME, true);
          CategoryParameterOption categoryParameterOption =
-             new CategoryParameterOption(APP_ID_VID, OPTION_NAME, categoryParameter);
-         categoryParameter.getOptions().add(categoryParameterOption);
+             new CategoryParameterOption(APP_ID_VID, OPTION_NAME, anotherCategoryParameter);
+         categoryParameter.addOption(categoryParameterOption);
          List<CategoryParameter> aList = createCategoryParametersList(categoryParameter);
  
 -        doReturn(aList).when(dataAccessService).getList(anyObject(), anyString(), anyString(), anyObject());
 +        doReturn(aList).when(dataAccessService).getList(any(), anyString(), any(), any());
  
          testSubject.deleteCategoryOption(CATEGORY_NAME, categoryParameterOption);
  
          verify(dataAccessService, times(1))
 -            .deleteDomainObject(anyObject(), anyObject());
 +            .deleteDomainObject(any(), any());
      }
  
      @Test
      public void getCategoryParametersTest() {
          CategoryParameter categoryParameter = createCategoryParameter(CATEGORY_NAME, true);
+         CategoryParameter anotherCategoryParameter = createCategoryParameter(CATEGORY_NAME, true);
          CategoryParameterOption categoryParameterOption =
-             new CategoryParameterOption(APP_ID_VID, OPTION_NAME, categoryParameter);
-         categoryParameter.getOptions().add(categoryParameterOption);
+             new CategoryParameterOption(APP_ID_VID, OPTION_NAME, anotherCategoryParameter);
+         categoryParameter.addOption(categoryParameterOption);
          List<CategoryParameter> aList = createCategoryParametersList(categoryParameter);
  
 -        doReturn(aList).when(dataAccessService).getList(anyObject(), anyString(), anyString(), anyObject());
 +        doReturn(aList).when(dataAccessService).getList(any(), anyString(), any(), any());
  
          CategoryParametersResponse response = testSubject.getCategoryParameters(Family.PARAMETER_STANDARDIZATION);
  
          Assert.assertTrue(response.getCategoryParameters().containsKey(CATEGORY_NAME));
  
          verify(dataAccessService, times(1))
 -            .getList(anyObject(), anyString(), anyString(), anyObject());
 +            .getList(any(), anyString(), any(), any());
      }
  
      @Test
      public void updateCategoryParameterOption_domainObjectGetsSavedSuccessfully() {
          CategoryParameterOptionRep optionRepExisting = new CategoryParameterOptionRep(APP_ID_VID, OPTION_NAME);
          CategoryParameter categoryParameter = createCategoryParameter(CATEGORY_NAME, true);
-         categoryParameter.getOptions().add(
-             new CategoryParameterOption(APP_ID_VID, UNIQUE_OPTION_NAME, categoryParameter));
+         CategoryParameter anotherCategoryParameter = createCategoryParameter(CATEGORY_NAME, true);
+         categoryParameter.addOption(
+             new CategoryParameterOption(APP_ID_VID, UNIQUE_OPTION_NAME, anotherCategoryParameter));
          List<CategoryParameter> aList = createCategoryParametersList(categoryParameter);
  
          doReturn(aList).when(dataAccessService).getList(CategoryParameter.class, QUERY_STRING_FOR_CATEGORY_NAME, null, null);
          AddCategoryOptionResponse result = testSubject.updateCategoryParameterOption(CATEGORY_NAME, optionRepExisting);
  
          verify(dataAccessService, times(1))
 -            .saveDomainObject(anyObject(), anyObject());
 +            .saveDomainObject(any(), any());
      }
  
      @Test(expectedExceptions = { ForbiddenException.class })
      public void updateCategoryParameterOption_shouldFailUpdateForbidden() {
          CategoryParameterOptionRep optionRep = new CategoryParameterOptionRep("1", CATEGORY_NAME);
          CategoryParameter categoryParameter = createCategoryParameter(CATEGORY_NAME, false);
-         categoryParameter.getOptions().add(new CategoryParameterOption(APP_ID_VID, OPTION_NAME, categoryParameter));
+         CategoryParameter anotherCategoryParameter = createCategoryParameter(CATEGORY_NAME, false);
+         categoryParameter.addOption(new CategoryParameterOption(APP_ID_VID, OPTION_NAME, anotherCategoryParameter));
          List<CategoryParameter> aList = createCategoryParametersList(categoryParameter);
  
          doReturn(aList).when(dataAccessService).getList(CategoryParameter.class, QUERY_STRING_FOR_CATEGORY_NAME, null, null);
          CategoryParameterOptionRep optionRep = new CategoryParameterOptionRep("SOME_UNRELATED_ID", CATEGORY_NAME);
  
          CategoryParameter categoryParameter = createCategoryParameter(CATEGORY_NAME, true);
-         categoryParameter.getOptions().add(new CategoryParameterOption(APP_ID_VID, OPTION_NAME, categoryParameter));
+         CategoryParameter anotherCategoryParameter = createCategoryParameter(CATEGORY_NAME, true);
+         categoryParameter.addOption(new CategoryParameterOption(APP_ID_VID, OPTION_NAME, anotherCategoryParameter));
          List<CategoryParameter> aList = createCategoryParametersList(categoryParameter);
  
          doReturn(aList).when(dataAccessService).getList(CategoryParameter.class, QUERY_STRING_FOR_CATEGORY_NAME, null, null);
  
          CategoryParameter categoryParameter = createCategoryParameter(CATEGORY_NAME, true);
          CategoryParameter anotherCategoryParameter = createCategoryParameter(CATEGORY_NAME, true);
-         categoryParameter.getOptions().add(
+         categoryParameter.addOption(
              new CategoryParameterOption(APP_ID_VID, UNIQUE_OPTION_NAME, anotherCategoryParameter));
-         categoryParameter.getOptions().add(
+         categoryParameter.addOption(
              new CategoryParameterOption(APP_ID_SDC, OPTION_NAME, anotherCategoryParameter));
          List<CategoryParameter> aList = createCategoryParametersList(categoryParameter);