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=========================================================
20 package org.onap.policy.xacml.action;
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.onap.policy.xacml.custom.OnapFunctionDefinitionFactory;
29 import com.att.research.xacml.api.Decision;
30 import com.att.research.xacml.api.Request;
31 import com.att.research.xacml.api.XACML3;
32 import com.att.research.xacml.std.StdAttributeValue;
33 import com.att.research.xacml.std.StdMutableAdvice;
34 import com.att.research.xacml.std.StdMutableAttributeAssignment;
35 import com.att.research.xacml.std.StdMutableMissingAttributeDetail;
36 import com.att.research.xacml.std.StdMutableObligation;
37 import com.att.research.xacml.std.StdMutableResponse;
38 import com.att.research.xacml.std.StdMutableResult;
39 import com.att.research.xacml.std.StdMutableStatus;
40 import com.att.research.xacml.std.StdMutableStatusDetail;
41 import com.att.research.xacml.std.StdStatusCode;
42 import com.att.research.xacml.std.datatypes.DataTypes;
43 import com.att.research.xacml.std.json.JSONRequest;
46 public class FindActionTest {
48 String xPathExampleFromSpec = "{ " +
53 "\"Id\" : \"urn:oasis:names:tc:xacml:3.0:content-selector\", " +
54 "\"DataType\" : \"xpathExpression\", " +
56 "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", " +
57 "\"Namespaces\" : [{ " +
58 "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " +
61 "\"Prefix\" : \"md\", " +
62 "\"Namespace\" : \"urn:example:med:schemas:record\" " +
65 "\"XPath\" : \"md:record/md:patient/md:patientDoB\" " +
78 public void setUp() throws Exception {
79 new OnapFunctionDefinitionFactory();
80 request = JSONRequest.load(xPathExampleFromSpec);
84 public final void testRun() {
85 FindAction action = new FindAction();
86 // fully-loaded multiple response
87 StdMutableResponse response = new StdMutableResponse();
88 // create a Status object
89 StdMutableStatus status = new StdMutableStatus(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
90 status.setStatusMessage("some status message");
91 StdMutableStatusDetail statusDetailIn = new StdMutableStatusDetail();
92 StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail();
93 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "PEPACTION"));
94 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_INTEGER.getId(), "PDPACTION"));
95 mad.setAttributeId(XACML3.ID_ACTION_PURPOSE);
96 mad.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION);
97 mad.setDataTypeId(XACML3.ID_DATATYPE_STRING);
98 mad.setIssuer("an Issuer");
99 statusDetailIn.addMissingAttributeDetail(mad);
100 status.setStatusDetail(statusDetailIn);
101 // create a single result object
102 StdMutableResult result = new StdMutableResult(status);
104 result.setDecision(Decision.INDETERMINATE);
105 // put the Result into the Response
106 response.add(result);
107 // create a new Result with a different Decision
108 status = new StdMutableStatus(StdStatusCode.STATUS_CODE_OK);
109 result = new StdMutableResult(status);
110 result.setDecision(Decision.DENY);
112 StdMutableObligation obligation = new StdMutableObligation();
113 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
114 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
115 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
117 "obligation-issuer1",
118 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Test")));
119 result.addObligation(obligation);
121 StdMutableAdvice advice = new StdMutableAdvice();
122 advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
123 advice.addAttributeAssignment(new StdMutableAttributeAssignment(
124 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
127 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Test")));
128 response.add(result);
130 assertTrue(action.run(response, request) != null);
131 } catch (Exception e) {
132 fail("operation failed, e="+e);