2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.xacml.pdp.application.optimization;
25 import static org.assertj.core.api.Assertions.assertThat;
27 import com.att.research.xacml.api.Request;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.common.utils.coder.StandardCoder;
35 import org.onap.policy.common.utils.resources.TextFileUtils;
36 import org.onap.policy.models.decisions.concepts.DecisionRequest;
38 public class OptimizationSubscriberRequestTest {
39 private static StandardCoder gson = new StandardCoder();
40 private DecisionRequest request;
43 * setupLoadDecision loads the decision request object for testing.
45 * @throws Exception Exception if unable to load
48 public void setupLoadDecision() throws Exception {
49 request = gson.decode(
52 "src/test/resources/decision.optimization.input.json"),
53 DecisionRequest.class);
55 assertThat(request).isNotNull();
59 public void testDecisionRequest() throws Exception {
63 Map<String, Object> context = new HashMap<>();
64 context.put("subscriberRole", "role1");
65 request.setContext(context);
67 // Check the return object
69 Request xacml = OptimizationSubscriberRequest.createInstance(request);
71 assertThat(xacml).isNotNull();
72 assertThat(xacml.getRequestAttributes()).hasSize(4);
74 List<String> roles = new ArrayList<>();
77 context.put("subscriberRole", "role1");
78 request.setContext(context);
80 xacml = OptimizationSubscriberRequest.createInstance(request);
81 assertThat(xacml).isNotNull();
82 assertThat(xacml.getRequestAttributes()).hasSize(4);