2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
26 import java.io.StringReader;
27 import java.util.HashMap;
28 import java.util.Properties;
30 import javax.xml.parsers.DocumentBuilder;
31 import javax.xml.parsers.DocumentBuilderFactory;
33 import org.openecomp.policy.pypdp.model_pojo.PyPolicyConfig;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.openecomp.policy.api.PolicyConfigStatus;
38 import org.openecomp.policy.api.PolicyType;
39 import org.openecomp.policy.std.StdPolicyConfig;
40 import org.w3c.dom.Document;
41 import org.xml.sax.InputSource;
43 import org.openecomp.policy.pypdp.ConfigRequest;
45 public class ConfigRequestTest {
47 private StdPolicyConfig config;
48 private ConfigRequest request;
52 request = new ConfigRequest(null);
53 config = new StdPolicyConfig();
54 config.setPolicyConfigStatus(PolicyConfigStatus.CONFIG_RETRIEVED);
58 public void checkResponsePropertiesTest() {
59 config.setPolicyType(PolicyType.PROPERTIES);
60 Properties prop = new Properties();
61 prop.put("Key", "value");
62 config.setProperties(prop);
63 PyPolicyConfig pConfig = request.checkResponse(config);
64 HashMap<String, String> result = new HashMap<String, String>();
65 result.put("Key", "value");
66 assertEquals(pConfig.getProperty(), result);
70 public void checkResponseDocumentTest() throws Exception {
71 config.setPolicyType(PolicyType.XML);
72 String xmlString = "<test></test>";
73 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
74 DocumentBuilder builder;
75 builder = factory.newDocumentBuilder();
76 Document document = builder.parse(new InputSource(new StringReader(
78 config.setDocument(document);
79 PyPolicyConfig pConfig = request.checkResponse(config);
80 assertNotNull(pConfig.getConfig());