blob: 834e0ec786b1e7ec42e0804234e183d932f77047 [file] [log] [blame]
Thomas Vachuskaf9c84362015-04-15 11:20:45 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onlab.stc;
17
18import com.google.common.base.MoreObjects;
19import org.onlab.graph.Vertex;
20
21import java.util.Objects;
22
23import static com.google.common.base.Preconditions.checkNotNull;
24
25/**
26 * Representation of a test step.
27 */
28public class Step implements Vertex {
29
30 protected final String name;
31 protected final String command;
32 protected final Group group;
33
34 /**
35 * Creates a new test step.
36 *
37 * @param name step name
38 * @param command step command to execute
39 * @param group optional group to which this step belongs
40 */
41 public Step(String name, String command, Group group) {
42 this.name = checkNotNull(name, "Name cannot be null");
43 this.group = group;
44
45 // Set the command; if one is not given default to the enclosing group
46 this.command = command != null ? command :
47 group != null && group.command != null ? group.command : null;
48 }
49
50 /**
51 * Returns the step name.
52 *
53 * @return step name
54 */
55 public String name() {
56 return name;
57 }
58
59 /**
60 * Returns the step command string.
61 *
62 * @return command string
63 */
64 public String command() {
65 return command;
66 }
67
68 /**
69 * Returns the enclosing group; null if none.
70 *
71 * @return enclosing group or null
72 */
73 public Group group() {
74 return group;
75 }
76
77
78 @Override
79 public int hashCode() {
80 return Objects.hash(name);
81 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (this == obj) {
86 return true;
87 }
88 if (obj instanceof Step) {
89 final Step other = (Step) obj;
90 return Objects.equals(this.name, other.name);
91 }
92 return false;
93 }
94
95 @Override
96 public String toString() {
97 return MoreObjects.toStringHelper(this)
98 .add("name", name)
99 .add("command", command)
100 .add("group", group)
101 .toString();
102 }
103}