2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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=========================================================
21 package org.onap.policy.drools.pooling.message;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
26 import org.junit.Test;
29 * Superclass used to test subclasses of {@link MessageWithAssignments}.
31 * @param <T> type of {@link MessageWithAssignments} subclass that this tests
33 public abstract class SupportMessageWithAssignmentsTester<T extends MessageWithAssignments>
34 extends SupportBasicMessageTester<T> {
35 // values set by makeValidMessage()
36 public static final String[] VALID_ARRAY = {VALID_HOST, VALID_HOST + "_xxx"};
37 public static final BucketAssignments VALID_ASGN = new BucketAssignments(VALID_ARRAY);
40 * {@code True} if {@code null} assignments are allowed, {@code false}
43 private boolean nullAssignments;
48 * @param subclazz subclass of {@link MessageWithAssignments} being tested
50 public SupportMessageWithAssignmentsTester(Class<T> subclazz) {
55 * Indicates whether or not {@code null} assignments should be used for the
58 * @param nullAssignments {@code true} to use {@code null} assignments,
59 * {@code false} otherwise
61 public void setNullAssignments(boolean nullAssignments) {
62 this.nullAssignments = nullAssignments;
65 public boolean isNullAssignments() {
66 return nullAssignments;
70 public void testCheckValidity_InvalidFields() throws Exception {
71 // null source (i.e., superclass field)
72 expectCheckValidityFailure(msg -> msg.setSource(null));
75 expectCheckValidityFailure(msg -> msg.setAssignments(new BucketAssignments(new String[0])));
78 String[] invalidAssignment = {"abc", null};
79 expectCheckValidityFailure(msg -> msg.setAssignments(new BucketAssignments(invalidAssignment)));
83 public void testGetAssignments_testSetAssignments() {
84 MessageWithAssignments msg = makeValidMessage();
87 assertEquals(VALID_ASGN, msg.getAssignments());
89 BucketAssignments asgn = new BucketAssignments();
90 msg.setAssignments(asgn);
91 assertEquals(asgn, msg.getAssignments());
95 public void testDefaultConstructorFields(T msg) {
96 super.testDefaultConstructorFields(msg);
98 assertNull(msg.getAssignments());
102 public void testValidFields(T msg) {
103 super.testValidFields(msg);
105 if (nullAssignments) {
106 assertNull(msg.getAssignments());
109 assertEquals(VALID_ASGN, msg.getAssignments());