/*-
* ============LICENSE_START=======================================================
* ONAP Policy Engine
* ================================================================================
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Modifications Copyright (C) 2019 Samsung
* ================================================================================
* 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.onap.policy.controller;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.fge.jackson.JsonLoader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.rest.adapter.PolicyRestAdapter;
import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.ConfigurationDataEntity;
import org.onap.policy.rest.jpa.MicroServiceModels;
import org.onap.policy.rest.jpa.PolicyEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
/**
* The class CreateDcaeMicroServiceControllerTest contains tests for the class
*
*
All JUnits are designed to run in the local development environment where they have write privileges
* and can execute time-sensitive tasks.
*
*/
public class CreateDcaeMicroServiceControllerTest {
private static Logger logger = FlexLogger.getLogger(CreateDcaeMicroServiceControllerTest.class);
private static CommonClassDao commonClassDao;
private String jsonString = null;
private String configBodyString = null;
private HttpServletRequest request = null;
/**
* setUp.
*
* @throws Exception should not throw one
*/
@Before
public void setUp() throws Exception {
logger.info("setUp: Entering");
commonClassDao = mock(CommonClassDao.class);
MicroServiceModels testData = new MicroServiceModels();
testData.setVersion("OpenOnap-Junit");
testData.setModelName("modelName");
testData.setRuleFormation("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, "
+ "Contains, FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures."
+ "symptomSignature[symptomVnfType, symptomContains, symptomFilterValue]");
testData.setAttributes(
"ParentCorrelation Name=String:defaultValue-null:required-true:MANY-false:description-null,"
+ "CorrelationWindow=String:defaultValue-null:required-true:MANY-false:description-null,"
+ "EmailNotification=String:defaultValue-null:required-true:MANY-false:description-null,"
+ "CorrelationPriority=string:defaultValue-null:required-true:MANY-false:description-null,");
testData.setRefAttributes("SymptomTriggerSignature=resource-model-symptomEntity:MANY-true:description-null,"
+ "triggerSignature=resource-model-entity:MANY-true:description-null,"
+ "SelectServerScope=SELECTSERVERSCOPE:MANY-false,logicalConnector=LOGICALCONNECTOR:MANY-false,"
+ "ParentCorrelationTraversal=PARENTCORRELATIONTRAVERSAL:MANY-false,");
testData.setSubAttributes(
"{\"symptomAlarms\":{\"symptomContains\":\"SYMPTOMCONTAINS:defaultValue-null:required-true:MANY-false:"
+ "description-null\",\"symptomFilterValue\":\"string:defaultValue-null:"
+ "required-true:MANY-false:"
+ "description-null\",\"symptomVnfType\":\"SYMPTOMVNFTYPE:defaultValue-null:"
+ "required-true:MANY-false:"
+ "description-null\"},\"symptomElement\":{\"symptomSignatures\":\"symptomRange:required-true:"
+ "MANY-true:description-null\",\"symptomTraversal\":\"SYMPTOMTRAVERSAL:defaultValue-null:"
+ "required-true:MANY-false:description-null\"},\"alarms\":{\"Contains\":\"CONTAINS:"
+ "defaultValue-null:required-true:MANY-false:description-null\",\"VnfType\":\"VNFTYPE:"
+ "defaultValue-null:required-true:MANY-false:description-null\",\"FilterValue\":\"string:"
+ "defaultValue-null:required-true:MANY-false:description-null\"},\"resource-model-entity\":"
+ "{\"signaturesAlarm\":\"element:required-false:MANY-false:description-null\"},\"range\":"
+ "{\"alarmSignature\":\"alarms:required-true:MANY-false:description-null\"},\"symptomRange\":"
+ "{\"symptomSignature\":\"symptomAlarms:required-true:MANY-false:description-null\"},"
+ "\"element\":"
+ "{\"alarmSignatures\":\"range:required-true:MANY-true:description-null\",\"traversal\":"
+ "\"TRAVERSAL:" + "defaultValue-null:required-true:MANY-false:description-null\"},"
+ "\"resource-model-symptomEntity\":"
+ "{\"signaturesSymptom\":\"symptomElement:required-false:MANY-false:description-null\"}}");
testData.setAnnotation(
"alarmSignatures=matching-true, symptomContains=matching-true, symptomSignatures=matching-true, "
+ "symptomTraversal=matching-true, symptomVnfType=matching-true, Contains=matching-true, "
+ "SelectServerScope=matching-true, VnfType=matching-true, traversal=matching-true, "
+ "logicalConnector=matching-true, ParentCorrelationTraversal=matching-true");
testData.setEnumValues("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, Contains, "
+ "FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures.symptomSignature"
+ "[symptomVnfType, symptomContains, symptomFilterValue]");
testData.setDataOrderInfo("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, Contains, "
+ "FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures."
+ "symptomSignature[symptomVnfType, symptomContains, symptomFilterValue]");
List