Ray Milkey
Committed by Gerrit Code Review

Coverage and SONAR improvements for Objectives classes

- cleaned up constructors to take a builder rather
  than a long list of parameters
- improved coverage of unit tests
- added missing APIs to builder interfaces

Change-Id: I4c4eac302d41f785d401f21e9935bc659ca5f892
...@@ -47,39 +47,19 @@ public final class DefaultFilteringObjective implements FilteringObjective { ...@@ -47,39 +47,19 @@ public final class DefaultFilteringObjective implements FilteringObjective {
47 private final Operation op; 47 private final Operation op;
48 private final Optional<ObjectiveContext> context; 48 private final Optional<ObjectiveContext> context;
49 49
50 - private DefaultFilteringObjective(Type type, boolean permanent, int timeout, 50 + private DefaultFilteringObjective(Builder builder) {
51 - ApplicationId appId, int priority, Criterion key, 51 + this.key = builder.key;
52 - List<Criterion> conditions, Operation op) { 52 + this.type = builder.type;
53 - this.key = key; 53 + this.permanent = builder.permanent;
54 - this.type = type; 54 + this.timeout = builder.timeout;
55 - this.permanent = permanent; 55 + this.appId = builder.appId;
56 - this.timeout = timeout; 56 + this.priority = builder.priority;
57 - this.appId = appId; 57 + this.conditions = builder.conditions;
58 - this.priority = priority; 58 + this.op = builder.op;
59 - this.conditions = conditions; 59 + this.context = Optional.ofNullable(builder.context);
60 - this.op = op;
61 - this.context = Optional.empty();
62 60
63 this.id = Objects.hash(type, key, conditions, permanent, 61 this.id = Objects.hash(type, key, conditions, permanent,
64 - timeout, appId, priority); 62 + timeout, appId, priority);
65 - }
66 -
67 - public DefaultFilteringObjective(Type type, boolean permanent, int timeout,
68 - ApplicationId appId, int priority, Criterion key,
69 - List<Criterion> conditions,
70 - ObjectiveContext context, Operation op) {
71 - this.key = key;
72 - this.type = type;
73 - this.permanent = permanent;
74 - this.timeout = timeout;
75 - this.appId = appId;
76 - this.priority = priority;
77 - this.conditions = conditions;
78 - this.op = op;
79 - this.context = Optional.ofNullable(context);
80 -
81 - this.id = Objects.hash(type, key, conditions, permanent,
82 - timeout, appId, priority);
83 } 63 }
84 64
85 @Override 65 @Override
...@@ -152,6 +132,9 @@ public final class DefaultFilteringObjective implements FilteringObjective { ...@@ -152,6 +132,9 @@ public final class DefaultFilteringObjective implements FilteringObjective {
152 private ApplicationId appId; 132 private ApplicationId appId;
153 private int priority = DEFAULT_PRIORITY; 133 private int priority = DEFAULT_PRIORITY;
154 private Criterion key = Criteria.dummy(); 134 private Criterion key = Criteria.dummy();
135 + private List<Criterion> conditions;
136 + private Operation op;
137 + private ObjectiveContext context;
155 138
156 @Override 139 @Override
157 public Builder withKey(Criterion key) { 140 public Builder withKey(Criterion key) {
...@@ -204,54 +187,50 @@ public final class DefaultFilteringObjective implements FilteringObjective { ...@@ -204,54 +187,50 @@ public final class DefaultFilteringObjective implements FilteringObjective {
204 187
205 @Override 188 @Override
206 public FilteringObjective add() { 189 public FilteringObjective add() {
207 - List<Criterion> conditions = listBuilder.build(); 190 + conditions = listBuilder.build();
191 + op = Operation.ADD;
208 checkNotNull(type, "Must have a type."); 192 checkNotNull(type, "Must have a type.");
209 checkArgument(!conditions.isEmpty(), "Must have at least one condition."); 193 checkArgument(!conditions.isEmpty(), "Must have at least one condition.");
210 checkNotNull(appId, "Must supply an application id"); 194 checkNotNull(appId, "Must supply an application id");
211 195
212 - return new DefaultFilteringObjective(type, permanent, timeout, 196 + return new DefaultFilteringObjective(this);
213 - appId, priority, key, conditions,
214 - Operation.ADD);
215 197
216 } 198 }
217 199
218 @Override 200 @Override
219 public FilteringObjective remove() { 201 public FilteringObjective remove() {
220 - List<Criterion> conditions = listBuilder.build(); 202 + conditions = listBuilder.build();
221 checkNotNull(type, "Must have a type."); 203 checkNotNull(type, "Must have a type.");
222 checkArgument(!conditions.isEmpty(), "Must have at least one condition."); 204 checkArgument(!conditions.isEmpty(), "Must have at least one condition.");
223 checkNotNull(appId, "Must supply an application id"); 205 checkNotNull(appId, "Must supply an application id");
206 + op = Operation.REMOVE;
224 207
225 - 208 + return new DefaultFilteringObjective(this);
226 - return new DefaultFilteringObjective(type, permanent, timeout,
227 - appId, priority, key, conditions,
228 - Operation.REMOVE);
229 209
230 } 210 }
231 211
232 @Override 212 @Override
233 public FilteringObjective add(ObjectiveContext context) { 213 public FilteringObjective add(ObjectiveContext context) {
234 - List<Criterion> conditions = listBuilder.build(); 214 + conditions = listBuilder.build();
235 checkNotNull(type, "Must have a type."); 215 checkNotNull(type, "Must have a type.");
236 checkArgument(!conditions.isEmpty(), "Must have at least one condition."); 216 checkArgument(!conditions.isEmpty(), "Must have at least one condition.");
237 checkNotNull(appId, "Must supply an application id"); 217 checkNotNull(appId, "Must supply an application id");
218 + op = Operation.ADD;
219 + this.context = context;
238 220
239 - return new DefaultFilteringObjective(type, permanent, timeout, 221 + return new DefaultFilteringObjective(this);
240 - appId, priority, key, conditions,
241 - context, Operation.ADD);
242 } 222 }
243 223
244 @Override 224 @Override
245 public FilteringObjective remove(ObjectiveContext context) { 225 public FilteringObjective remove(ObjectiveContext context) {
246 - List<Criterion> conditions = listBuilder.build(); 226 + conditions = listBuilder.build();
247 checkNotNull(type, "Must have a type."); 227 checkNotNull(type, "Must have a type.");
248 checkArgument(!conditions.isEmpty(), "Must have at least one condition."); 228 checkArgument(!conditions.isEmpty(), "Must have at least one condition.");
249 checkNotNull(appId, "Must supply an application id"); 229 checkNotNull(appId, "Must supply an application id");
230 + op = Operation.REMOVE;
231 + this.context = context;
250 232
251 - 233 + return new DefaultFilteringObjective(this);
252 - return new DefaultFilteringObjective(type, permanent, timeout,
253 - appId, priority, key, conditions,
254 - context, Operation.REMOVE);
255 } 234 }
256 235
257 236
......
...@@ -45,47 +45,21 @@ public final class DefaultForwardingObjective implements ForwardingObjective { ...@@ -45,47 +45,21 @@ public final class DefaultForwardingObjective implements ForwardingObjective {
45 45
46 private final int id; 46 private final int id;
47 47
48 - private DefaultForwardingObjective(TrafficSelector selector, 48 + private DefaultForwardingObjective(Builder builder) {
49 - Flag flag, boolean permanent, 49 + this.selector = builder.selector;
50 - int timeout, ApplicationId appId, 50 + this.flag = builder.flag;
51 - int priority, Integer nextId, 51 + this.permanent = builder.permanent;
52 - TrafficTreatment treatment, Operation op) { 52 + this.timeout = builder.timeout;
53 - this.selector = selector; 53 + this.appId = builder.appId;
54 - this.flag = flag; 54 + this.priority = builder.priority;
55 - this.permanent = permanent; 55 + this.nextId = builder.nextId;
56 - this.timeout = timeout; 56 + this.treatment = builder.treatment;
57 - this.appId = appId; 57 + this.op = builder.op;
58 - this.priority = priority; 58 + this.context = Optional.ofNullable(builder.context);
59 - this.nextId = nextId;
60 - this.treatment = treatment;
61 - this.op = op;
62 - this.context = Optional.empty();
63 59
64 this.id = Objects.hash(selector, flag, permanent, 60 this.id = Objects.hash(selector, flag, permanent,
65 - timeout, appId, priority, nextId, 61 + timeout, appId, priority, nextId,
66 - treatment, op); 62 + treatment, op);
67 - }
68 -
69 - private DefaultForwardingObjective(TrafficSelector selector,
70 - Flag flag, boolean permanent,
71 - int timeout, ApplicationId appId,
72 - int priority, Integer nextId,
73 - TrafficTreatment treatment,
74 - ObjectiveContext context, Operation op) {
75 - this.selector = selector;
76 - this.flag = flag;
77 - this.permanent = permanent;
78 - this.timeout = timeout;
79 - this.appId = appId;
80 - this.priority = priority;
81 - this.nextId = nextId;
82 - this.treatment = treatment;
83 - this.op = op;
84 - this.context = Optional.ofNullable(context);
85 -
86 - this.id = Objects.hash(selector, flag, permanent,
87 - timeout, appId, priority, nextId,
88 - treatment, op);
89 } 63 }
90 64
91 65
...@@ -164,6 +138,8 @@ public final class DefaultForwardingObjective implements ForwardingObjective { ...@@ -164,6 +138,8 @@ public final class DefaultForwardingObjective implements ForwardingObjective {
164 private ApplicationId appId; 138 private ApplicationId appId;
165 private Integer nextId; 139 private Integer nextId;
166 private TrafficTreatment treatment; 140 private TrafficTreatment treatment;
141 + private Operation op;
142 + private ObjectiveContext context;
167 143
168 @Override 144 @Override
169 public Builder withSelector(TrafficSelector selector) { 145 public Builder withSelector(TrafficSelector selector) {
...@@ -221,9 +197,8 @@ public final class DefaultForwardingObjective implements ForwardingObjective { ...@@ -221,9 +197,8 @@ public final class DefaultForwardingObjective implements ForwardingObjective {
221 checkArgument(nextId != null || treatment != null, "Must supply at " + 197 checkArgument(nextId != null || treatment != null, "Must supply at " +
222 "least a treatment and/or a nextId"); 198 "least a treatment and/or a nextId");
223 checkNotNull(appId, "Must supply an application id"); 199 checkNotNull(appId, "Must supply an application id");
224 - return new DefaultForwardingObjective(selector, flag, permanent, 200 + op = Operation.ADD;
225 - timeout, appId, priority, 201 + return new DefaultForwardingObjective(this);
226 - nextId, treatment, Operation.ADD);
227 } 202 }
228 203
229 @Override 204 @Override
...@@ -233,9 +208,8 @@ public final class DefaultForwardingObjective implements ForwardingObjective { ...@@ -233,9 +208,8 @@ public final class DefaultForwardingObjective implements ForwardingObjective {
233 checkArgument(nextId != null || treatment != null, "Must supply at " + 208 checkArgument(nextId != null || treatment != null, "Must supply at " +
234 "least a treatment and/or a nextId"); 209 "least a treatment and/or a nextId");
235 checkNotNull(appId, "Must supply an application id"); 210 checkNotNull(appId, "Must supply an application id");
236 - return new DefaultForwardingObjective(selector, flag, permanent, 211 + op = Operation.REMOVE;
237 - timeout, appId, priority, 212 + return new DefaultForwardingObjective(this);
238 - nextId, treatment, Operation.REMOVE);
239 } 213 }
240 214
241 @Override 215 @Override
...@@ -245,10 +219,10 @@ public final class DefaultForwardingObjective implements ForwardingObjective { ...@@ -245,10 +219,10 @@ public final class DefaultForwardingObjective implements ForwardingObjective {
245 checkArgument(nextId != null || treatment != null, "Must supply at " + 219 checkArgument(nextId != null || treatment != null, "Must supply at " +
246 "least a treatment and/or a nextId"); 220 "least a treatment and/or a nextId");
247 checkNotNull(appId, "Must supply an application id"); 221 checkNotNull(appId, "Must supply an application id");
248 - return new DefaultForwardingObjective(selector, flag, permanent, 222 + op = Operation.ADD;
249 - timeout, appId, priority, 223 + this.context = context;
250 - nextId, treatment, 224 +
251 - context, Operation.ADD); 225 + return new DefaultForwardingObjective(this);
252 } 226 }
253 227
254 @Override 228 @Override
...@@ -258,10 +232,10 @@ public final class DefaultForwardingObjective implements ForwardingObjective { ...@@ -258,10 +232,10 @@ public final class DefaultForwardingObjective implements ForwardingObjective {
258 checkArgument(nextId != null || treatment != null, "Must supply at " + 232 checkArgument(nextId != null || treatment != null, "Must supply at " +
259 "least a treatment and/or a nextId"); 233 "least a treatment and/or a nextId");
260 checkNotNull(appId, "Must supply an application id"); 234 checkNotNull(appId, "Must supply an application id");
261 - return new DefaultForwardingObjective(selector, flag, permanent, 235 + op = Operation.REMOVE;
262 - timeout, appId, priority, 236 + this.context = context;
263 - nextId, treatment, 237 +
264 - context, Operation.REMOVE); 238 + return new DefaultForwardingObjective(this);
265 } 239 }
266 } 240 }
267 } 241 }
......
...@@ -40,25 +40,13 @@ public final class DefaultNextObjective implements NextObjective { ...@@ -40,25 +40,13 @@ public final class DefaultNextObjective implements NextObjective {
40 private final Operation op; 40 private final Operation op;
41 private final Optional<ObjectiveContext> context; 41 private final Optional<ObjectiveContext> context;
42 42
43 - private DefaultNextObjective(Integer id, List<TrafficTreatment> treatments, 43 + private DefaultNextObjective(Builder builder) {
44 - ApplicationId appId, Type type, Operation op) { 44 + this.treatments = builder.treatments;
45 - this.treatments = treatments; 45 + this.appId = builder.appId;
46 - this.appId = appId; 46 + this.type = builder.type;
47 - this.type = type; 47 + this.id = builder.id;
48 - this.id = id; 48 + this.op = builder.op;
49 - this.op = op; 49 + this.context = Optional.ofNullable(builder.context);
50 - this.context = Optional.empty();
51 - }
52 -
53 - private DefaultNextObjective(Integer id, List<TrafficTreatment> treatments,
54 - ApplicationId appId, ObjectiveContext context,
55 - Type type, Operation op) {
56 - this.treatments = treatments;
57 - this.appId = appId;
58 - this.type = type;
59 - this.id = id;
60 - this.op = op;
61 - this.context = Optional.ofNullable(context);
62 } 50 }
63 51
64 @Override 52 @Override
...@@ -120,12 +108,15 @@ public final class DefaultNextObjective implements NextObjective { ...@@ -120,12 +108,15 @@ public final class DefaultNextObjective implements NextObjective {
120 private ApplicationId appId; 108 private ApplicationId appId;
121 private Type type; 109 private Type type;
122 private Integer id; 110 private Integer id;
111 + private List<TrafficTreatment> treatments;
112 + private Operation op;
113 + private ObjectiveContext context;
123 114
124 private final ImmutableList.Builder<TrafficTreatment> listBuilder 115 private final ImmutableList.Builder<TrafficTreatment> listBuilder
125 = ImmutableList.builder(); 116 = ImmutableList.builder();
126 117
127 @Override 118 @Override
128 - public NextObjective.Builder withId(int nextId) { 119 + public Builder withId(int nextId) {
129 this.id = nextId; 120 this.id = nextId;
130 return this; 121 return this;
131 } 122 }
...@@ -164,7 +155,7 @@ public final class DefaultNextObjective implements NextObjective { ...@@ -164,7 +155,7 @@ public final class DefaultNextObjective implements NextObjective {
164 } 155 }
165 156
166 @Override 157 @Override
167 - public NextObjective.Builder fromApp(ApplicationId appId) { 158 + public Builder fromApp(ApplicationId appId) {
168 this.appId = appId; 159 this.appId = appId;
169 return this; 160 return this;
170 } 161 }
...@@ -182,46 +173,50 @@ public final class DefaultNextObjective implements NextObjective { ...@@ -182,46 +173,50 @@ public final class DefaultNextObjective implements NextObjective {
182 173
183 @Override 174 @Override
184 public NextObjective add() { 175 public NextObjective add() {
185 - List<TrafficTreatment> treatments = listBuilder.build(); 176 + treatments = listBuilder.build();
177 + op = Operation.ADD;
186 checkNotNull(appId, "Must supply an application id"); 178 checkNotNull(appId, "Must supply an application id");
187 checkNotNull(id, "id cannot be null"); 179 checkNotNull(id, "id cannot be null");
188 checkNotNull(type, "The type cannot be null"); 180 checkNotNull(type, "The type cannot be null");
189 checkArgument(!treatments.isEmpty(), "Must have at least one treatment"); 181 checkArgument(!treatments.isEmpty(), "Must have at least one treatment");
190 182
191 - return new DefaultNextObjective(id, treatments, appId, type, Operation.ADD); 183 + return new DefaultNextObjective(this);
192 } 184 }
193 185
194 @Override 186 @Override
195 public NextObjective remove() { 187 public NextObjective remove() {
196 - List<TrafficTreatment> treatments = listBuilder.build(); 188 + treatments = listBuilder.build();
189 + op = Operation.REMOVE;
197 checkNotNull(appId, "Must supply an application id"); 190 checkNotNull(appId, "Must supply an application id");
198 checkNotNull(id, "id cannot be null"); 191 checkNotNull(id, "id cannot be null");
199 checkNotNull(type, "The type cannot be null"); 192 checkNotNull(type, "The type cannot be null");
200 193
201 - return new DefaultNextObjective(id, treatments, appId, type, Operation.REMOVE); 194 + return new DefaultNextObjective(this);
202 } 195 }
203 196
204 @Override 197 @Override
205 public NextObjective add(ObjectiveContext context) { 198 public NextObjective add(ObjectiveContext context) {
206 - List<TrafficTreatment> treatments = listBuilder.build(); 199 + treatments = listBuilder.build();
200 + op = Operation.ADD;
201 + this.context = context;
207 checkNotNull(appId, "Must supply an application id"); 202 checkNotNull(appId, "Must supply an application id");
208 checkNotNull(id, "id cannot be null"); 203 checkNotNull(id, "id cannot be null");
209 checkNotNull(type, "The type cannot be null"); 204 checkNotNull(type, "The type cannot be null");
210 checkArgument(!treatments.isEmpty(), "Must have at least one treatment"); 205 checkArgument(!treatments.isEmpty(), "Must have at least one treatment");
211 206
212 - return new DefaultNextObjective(id, treatments, appId, 207 + return new DefaultNextObjective(this);
213 - context, type, Operation.ADD);
214 } 208 }
215 209
216 @Override 210 @Override
217 public NextObjective remove(ObjectiveContext context) { 211 public NextObjective remove(ObjectiveContext context) {
218 - List<TrafficTreatment> treatments = listBuilder.build(); 212 + treatments = listBuilder.build();
213 + op = Operation.REMOVE;
214 + this.context = context;
219 checkNotNull(appId, "Must supply an application id"); 215 checkNotNull(appId, "Must supply an application id");
220 checkNotNull(id, "id cannot be null"); 216 checkNotNull(id, "id cannot be null");
221 checkNotNull(type, "The type cannot be null"); 217 checkNotNull(type, "The type cannot be null");
222 218
223 - return new DefaultNextObjective(id, treatments, appId, 219 + return new DefaultNextObjective(this);
224 - context, type, Operation.REMOVE);
225 } 220 }
226 } 221 }
227 } 222 }
......
...@@ -112,10 +112,25 @@ public interface NextObjective extends Objective { ...@@ -112,10 +112,25 @@ public interface NextObjective extends Objective {
112 */ 112 */
113 Builder addTreatment(TrafficTreatment treatment); 113 Builder addTreatment(TrafficTreatment treatment);
114 114
115 + /**
116 + * Specifies the application which applied the filter.
117 + *
118 + * @param appId an application id
119 + * @return an objective builder
120 + */
115 @Override 121 @Override
116 Builder fromApp(ApplicationId appId); 122 Builder fromApp(ApplicationId appId);
117 123
118 /** 124 /**
125 + * Sets the priority for this objective.
126 + *
127 + * @param priority an integer
128 + * @return an objective builder
129 + */
130 + @Override
131 + Builder withPriority(int priority);
132 +
133 + /**
119 * Builds the next objective that will be added. 134 * Builds the next objective that will be added.
120 * 135 *
121 * @return a next objective 136 * @return a next objective
......
...@@ -25,12 +25,16 @@ import org.onosproject.net.flow.criteria.Criterion; ...@@ -25,12 +25,16 @@ import org.onosproject.net.flow.criteria.Criterion;
25 25
26 import static org.hamcrest.CoreMatchers.hasItem; 26 import static org.hamcrest.CoreMatchers.hasItem;
27 import static org.hamcrest.CoreMatchers.is; 27 import static org.hamcrest.CoreMatchers.is;
28 +import static org.hamcrest.CoreMatchers.nullValue;
28 import static org.hamcrest.MatcherAssert.assertThat; 29 import static org.hamcrest.MatcherAssert.assertThat;
30 +import static org.hamcrest.Matchers.not;
29 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; 31 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
30 import static org.onosproject.net.NetTestTools.APP_ID; 32 import static org.onosproject.net.NetTestTools.APP_ID;
31 import static org.onosproject.net.flowobjective.FilteringObjective.Type.DENY; 33 import static org.onosproject.net.flowobjective.FilteringObjective.Type.DENY;
32 import static org.onosproject.net.flowobjective.ForwardingObjective.Flag.SPECIFIC; 34 import static org.onosproject.net.flowobjective.ForwardingObjective.Flag.SPECIFIC;
33 import static org.onosproject.net.flowobjective.NextObjective.Type.HASHED; 35 import static org.onosproject.net.flowobjective.NextObjective.Type.HASHED;
36 +import static org.onosproject.net.flowobjective.Objective.Operation.ADD;
37 +import static org.onosproject.net.flowobjective.Objective.Operation.REMOVE;
34 38
35 /** 39 /**
36 * Unit tests for forwarding objective class. 40 * Unit tests for forwarding objective class.
...@@ -82,6 +86,8 @@ public class ObjectiveTest { ...@@ -82,6 +86,8 @@ public class ObjectiveTest {
82 .withTreatment(treatment) 86 .withTreatment(treatment)
83 .withFlag(SPECIFIC) 87 .withFlag(SPECIFIC)
84 .fromApp(APP_ID) 88 .fromApp(APP_ID)
89 + .withPriority(22)
90 + .makeTemporary(5)
85 .nextStep(33); 91 .nextStep(33);
86 } 92 }
87 93
...@@ -90,12 +96,24 @@ public class ObjectiveTest { ...@@ -90,12 +96,24 @@ public class ObjectiveTest {
90 * 96 *
91 * @param objective forwarding objective to check 97 * @param objective forwarding objective to check
92 */ 98 */
93 - private void checkForwardingBase(ForwardingObjective objective) { 99 + private void checkForwardingBase(ForwardingObjective objective,
100 + Objective.Operation op,
101 + ObjectiveContext expectedContext) {
102 + assertThat(objective.permanent(), is(false));
103 + assertThat(objective.timeout(), is(5));
94 assertThat(objective.selector(), is(selector)); 104 assertThat(objective.selector(), is(selector));
95 assertThat(objective.treatment(), is(treatment)); 105 assertThat(objective.treatment(), is(treatment));
96 assertThat(objective.flag(), is(SPECIFIC)); 106 assertThat(objective.flag(), is(SPECIFIC));
97 assertThat(objective.appId(), is(APP_ID)); 107 assertThat(objective.appId(), is(APP_ID));
98 assertThat(objective.nextId(), is(33)); 108 assertThat(objective.nextId(), is(33));
109 + assertThat(objective.id(), is(not(0)));
110 + assertThat(objective.priority(), is(22));
111 + assertThat(objective.op(), is(op));
112 + if (objective.context().isPresent()) {
113 + assertThat(objective.context().get(), is(expectedContext));
114 + } else {
115 + assertThat(expectedContext, nullValue());
116 + }
99 } 117 }
100 118
101 /** 119 /**
...@@ -104,7 +122,7 @@ public class ObjectiveTest { ...@@ -104,7 +122,7 @@ public class ObjectiveTest {
104 */ 122 */
105 @Test 123 @Test
106 public void testForwardingAdd() { 124 public void testForwardingAdd() {
107 - checkForwardingBase(baseForwardingBuilder().add()); 125 + checkForwardingBase(baseForwardingBuilder().add(), ADD, null);
108 } 126 }
109 127
110 /** 128 /**
...@@ -114,7 +132,7 @@ public class ObjectiveTest { ...@@ -114,7 +132,7 @@ public class ObjectiveTest {
114 @Test 132 @Test
115 public void testForwardingAddWithContext() { 133 public void testForwardingAddWithContext() {
116 ObjectiveContext context = new MockObjectiveContext(); 134 ObjectiveContext context = new MockObjectiveContext();
117 - checkForwardingBase(baseForwardingBuilder().add(context)); 135 + checkForwardingBase(baseForwardingBuilder().add(context), ADD, context);
118 } 136 }
119 137
120 /** 138 /**
...@@ -123,7 +141,7 @@ public class ObjectiveTest { ...@@ -123,7 +141,7 @@ public class ObjectiveTest {
123 */ 141 */
124 @Test 142 @Test
125 public void testForwardingRemove() { 143 public void testForwardingRemove() {
126 - checkForwardingBase(baseForwardingBuilder().remove()); 144 + checkForwardingBase(baseForwardingBuilder().remove(), REMOVE, null);
127 } 145 }
128 146
129 /** 147 /**
...@@ -133,7 +151,7 @@ public class ObjectiveTest { ...@@ -133,7 +151,7 @@ public class ObjectiveTest {
133 @Test 151 @Test
134 public void testForwardingRemoveWithContext() { 152 public void testForwardingRemoveWithContext() {
135 ObjectiveContext context = new MockObjectiveContext(); 153 ObjectiveContext context = new MockObjectiveContext();
136 - checkForwardingBase(baseForwardingBuilder().remove(context)); 154 + checkForwardingBase(baseForwardingBuilder().remove(context), REMOVE, context);
137 } 155 }
138 156
139 // Filtering objectives 157 // Filtering objectives
...@@ -158,7 +176,9 @@ public class ObjectiveTest { ...@@ -158,7 +176,9 @@ public class ObjectiveTest {
158 * 176 *
159 * @param objective filtering objective to check 177 * @param objective filtering objective to check
160 */ 178 */
161 - private void checkFilteringBase(FilteringObjective objective) { 179 + private void checkFilteringBase(FilteringObjective objective,
180 + Objective.Operation op,
181 + ObjectiveContext expectedContext) {
162 assertThat(objective.key(), is(key)); 182 assertThat(objective.key(), is(key));
163 assertThat(objective.conditions(), hasItem(criterion)); 183 assertThat(objective.conditions(), hasItem(criterion));
164 assertThat(objective.permanent(), is(false)); 184 assertThat(objective.permanent(), is(false));
...@@ -166,6 +186,13 @@ public class ObjectiveTest { ...@@ -166,6 +186,13 @@ public class ObjectiveTest {
166 assertThat(objective.priority(), is(5)); 186 assertThat(objective.priority(), is(5));
167 assertThat(objective.appId(), is(APP_ID)); 187 assertThat(objective.appId(), is(APP_ID));
168 assertThat(objective.type(), is(DENY)); 188 assertThat(objective.type(), is(DENY));
189 + assertThat(objective.id(), is(not(0)));
190 + assertThat(objective.op(), is(op));
191 + if (objective.context().isPresent()) {
192 + assertThat(objective.context().get(), is(expectedContext));
193 + } else {
194 + assertThat(expectedContext, nullValue());
195 + }
169 } 196 }
170 197
171 /** 198 /**
...@@ -174,7 +201,7 @@ public class ObjectiveTest { ...@@ -174,7 +201,7 @@ public class ObjectiveTest {
174 */ 201 */
175 @Test 202 @Test
176 public void testFilteringAdd() { 203 public void testFilteringAdd() {
177 - checkFilteringBase(baseFilteringBuilder().add()); 204 + checkFilteringBase(baseFilteringBuilder().add(), ADD, null);
178 } 205 }
179 206
180 /** 207 /**
...@@ -184,7 +211,7 @@ public class ObjectiveTest { ...@@ -184,7 +211,7 @@ public class ObjectiveTest {
184 @Test 211 @Test
185 public void testFilteringAddWithContext() { 212 public void testFilteringAddWithContext() {
186 ObjectiveContext context = new MockObjectiveContext(); 213 ObjectiveContext context = new MockObjectiveContext();
187 - checkFilteringBase(baseFilteringBuilder().add(context)); 214 + checkFilteringBase(baseFilteringBuilder().add(context), ADD, context);
188 } 215 }
189 216
190 /** 217 /**
...@@ -193,7 +220,7 @@ public class ObjectiveTest { ...@@ -193,7 +220,7 @@ public class ObjectiveTest {
193 */ 220 */
194 @Test 221 @Test
195 public void testFilteringRemove() { 222 public void testFilteringRemove() {
196 - checkFilteringBase(baseFilteringBuilder().remove()); 223 + checkFilteringBase(baseFilteringBuilder().remove(), REMOVE, null);
197 } 224 }
198 225
199 /** 226 /**
...@@ -203,7 +230,7 @@ public class ObjectiveTest { ...@@ -203,7 +230,7 @@ public class ObjectiveTest {
203 @Test 230 @Test
204 public void testFilteringRemoveWithContext() { 231 public void testFilteringRemoveWithContext() {
205 ObjectiveContext context = new MockObjectiveContext(); 232 ObjectiveContext context = new MockObjectiveContext();
206 - checkFilteringBase(baseFilteringBuilder().remove(context)); 233 + checkFilteringBase(baseFilteringBuilder().remove(context), REMOVE, context);
207 } 234 }
208 235
209 // Next objectives 236 // Next objectives
...@@ -218,6 +245,8 @@ public class ObjectiveTest { ...@@ -218,6 +245,8 @@ public class ObjectiveTest {
218 .addTreatment(treatment) 245 .addTreatment(treatment)
219 .withId(12) 246 .withId(12)
220 .withType(HASHED) 247 .withType(HASHED)
248 + .makeTemporary(777)
249 + .withPriority(33)
221 .fromApp(APP_ID); 250 .fromApp(APP_ID);
222 } 251 }
223 252
...@@ -226,11 +255,22 @@ public class ObjectiveTest { ...@@ -226,11 +255,22 @@ public class ObjectiveTest {
226 * 255 *
227 * @param objective next objective to check 256 * @param objective next objective to check
228 */ 257 */
229 - private void checkNextBase(NextObjective objective) { 258 + private void checkNextBase(NextObjective objective,
259 + Objective.Operation op,
260 + ObjectiveContext expectedContext) {
230 assertThat(objective.id(), is(12)); 261 assertThat(objective.id(), is(12));
231 assertThat(objective.appId(), is(APP_ID)); 262 assertThat(objective.appId(), is(APP_ID));
232 assertThat(objective.type(), is(HASHED)); 263 assertThat(objective.type(), is(HASHED));
233 assertThat(objective.next(), hasItem(treatment)); 264 assertThat(objective.next(), hasItem(treatment));
265 + assertThat(objective.permanent(), is(false));
266 + assertThat(objective.timeout(), is(0));
267 + assertThat(objective.priority(), is(0));
268 + assertThat(objective.op(), is(op));
269 + if (objective.context().isPresent()) {
270 + assertThat(objective.context().get(), is(expectedContext));
271 + } else {
272 + assertThat(expectedContext, nullValue());
273 + }
234 } 274 }
235 275
236 /** 276 /**
...@@ -239,7 +279,7 @@ public class ObjectiveTest { ...@@ -239,7 +279,7 @@ public class ObjectiveTest {
239 */ 279 */
240 @Test 280 @Test
241 public void testNextAdd() { 281 public void testNextAdd() {
242 - checkNextBase(baseNextBuilder().add()); 282 + checkNextBase(baseNextBuilder().add(), ADD, null);
243 } 283 }
244 284
245 /** 285 /**
...@@ -249,7 +289,7 @@ public class ObjectiveTest { ...@@ -249,7 +289,7 @@ public class ObjectiveTest {
249 @Test 289 @Test
250 public void testNextAddWithContext() { 290 public void testNextAddWithContext() {
251 ObjectiveContext context = new MockObjectiveContext(); 291 ObjectiveContext context = new MockObjectiveContext();
252 - checkNextBase(baseNextBuilder().add(context)); 292 + checkNextBase(baseNextBuilder().add(context), ADD, context);
253 } 293 }
254 294
255 /** 295 /**
...@@ -258,7 +298,7 @@ public class ObjectiveTest { ...@@ -258,7 +298,7 @@ public class ObjectiveTest {
258 */ 298 */
259 @Test 299 @Test
260 public void testNextRemove() { 300 public void testNextRemove() {
261 - checkNextBase(baseNextBuilder().remove()); 301 + checkNextBase(baseNextBuilder().remove(), REMOVE, null);
262 } 302 }
263 303
264 /** 304 /**
...@@ -268,6 +308,6 @@ public class ObjectiveTest { ...@@ -268,6 +308,6 @@ public class ObjectiveTest {
268 @Test 308 @Test
269 public void testNextRemoveWithContext() { 309 public void testNextRemoveWithContext() {
270 ObjectiveContext context = new MockObjectiveContext(); 310 ObjectiveContext context = new MockObjectiveContext();
271 - checkNextBase(baseNextBuilder().remove(context)); 311 + checkNextBase(baseNextBuilder().remove(context), REMOVE, context);
272 } 312 }
273 } 313 }
......