2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 
   6  * ================================================================================
 
   7  * Copyright (C) 2017 Amdocs
 
   8  * =============================================================================
 
   9  * Licensed under the Apache License, Version 2.0 (the "License");
 
  10  * you may not use this file except in compliance with the License.
 
  11  * You may obtain a copy of the License at
 
  13  *      http://www.apache.org/licenses/LICENSE-2.0
 
  15  * Unless required by applicable law or agreed to in writing, software
 
  16  * distributed under the License is distributed on an "AS IS" BASIS,
 
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  18  * See the License for the specific language governing permissions and
 
  19  * limitations under the License.
 
  21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 
  22  * ============LICENSE_END=========================================================
 
  25 package org.onap.appc.provider.lcm.util;
 
  27 import org.junit.Assert;
 
  28 import org.junit.Before;
 
  29 import org.junit.Test;
 
  30 import org.mockito.Mockito;
 
  31 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
 
  32 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ZULU;
 
  33 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
 
  34 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
 
  35 import org.onap.appc.executor.objects.LCMCommandStatus;
 
  37 import static org.mockito.Mockito.mock;
 
  39 public class ValidationServiceTest {
 
  40     private final Integer expectedErrorCode = Integer.valueOf(
 
  41         LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode());
 
  43     public void setUp() throws Exception {
 
  47     public void getInstance() throws Exception {
 
  48         Assert.assertEquals("Should always return the same instance",
 
  49             ValidationService.getInstance(), ValidationService.getInstance());
 
  53     public void validateInput() throws Exception {
 
  54         Status status = ValidationService.getInstance().validateInput(null, null, null);
 
  55         Assert.assertEquals("Should return error status", expectedErrorCode, status.getCode());
 
  56         Assert.assertTrue("Should include common-header in the message",
 
  57             status.getMessage().contains("common-header"));
 
  58         Assert.assertTrue("Should include action in the message",
 
  59             status.getMessage().contains("action"));
 
  61         CommonHeader mockCommonHeader = mock(CommonHeader.class);
 
  62         status = ValidationService.getInstance().validateInput(mockCommonHeader, Action.Query, "query");
 
  63         Assert.assertEquals("Should return error status", expectedErrorCode, status.getCode());
 
  64         Assert.assertFalse("Should not include action in the message",
 
  65             status.getMessage().contains("action"));
 
  67         Mockito.when(mockCommonHeader.getApiVer()).thenReturn("testing API version");
 
  68         status = ValidationService.getInstance().validateInput(mockCommonHeader, Action.Query, "query");
 
  69         Assert.assertEquals("Should return error status", expectedErrorCode, status.getCode());
 
  70         Assert.assertFalse("Should not include api-ver in the message",
 
  71             status.getMessage().contains("api-ver"));
 
  73         Mockito.when(mockCommonHeader.getOriginatorId()).thenReturn("testing originator id");
 
  74         status = ValidationService.getInstance().validateInput(mockCommonHeader, Action.Query, "query");
 
  75         Assert.assertEquals("Should return error status", expectedErrorCode, status.getCode());
 
  76         Assert.assertFalse("Should not include originator-id in the message",
 
  77             status.getMessage().contains("originator-id"));
 
  79         Mockito.when(mockCommonHeader.getRequestId()).thenReturn("testing request id");
 
  80         status = ValidationService.getInstance().validateInput(mockCommonHeader, Action.Query, "query");
 
  81         Assert.assertEquals("Should return error status", expectedErrorCode, status.getCode());
 
  82         Assert.assertFalse("Should not include request-id in the message",
 
  83             status.getMessage().contains("request-id"));
 
  85         Mockito.when(mockCommonHeader.getTimestamp()).thenReturn(mock(ZULU.class));
 
  86         status = ValidationService.getInstance().validateInput(mockCommonHeader, Action.Query, "query");
 
  87         Assert.assertTrue("Should return success", status == null);