blob: e14addb589061a0c86c0905d3beb2ad8bc94490e [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;
Thomas Vachuska4bfccd542015-05-30 00:35:25 -070032 protected final String env;
33 protected final String cwd;
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070034 protected final Group group;
35
36 /**
37 * Creates a new test step.
38 *
Thomas Vachuska4bfccd542015-05-30 00:35:25 -070039 * @param name step name
40 * @param command step command to execute
41 * @param env path to file to be sourced into the environment
42 * @param cwd path to current working directory for the step
43 * @param group optional group to which this step belongs
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070044 */
Thomas Vachuska4bfccd542015-05-30 00:35:25 -070045 public Step(String name, String command, String env, String cwd, Group group) {
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070046 this.name = checkNotNull(name, "Name cannot be null");
47 this.group = group;
48
Thomas Vachuska4bfccd542015-05-30 00:35:25 -070049 // Set the command, environment and cwd
50 // If one is not given use the value from the enclosing group
51 this.command = command != null ? command : group != null && group.command != null ? group.command : null;
52 this.env = env != null ? env : group != null && group.env != null ? group.env : null;
53 this.cwd = cwd != null ? cwd : group != null && group.cwd != null ? group.cwd : null;
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070054 }
55
56 /**
57 * Returns the step name.
58 *
59 * @return step name
60 */
61 public String name() {
62 return name;
63 }
64
65 /**
66 * Returns the step command string.
67 *
68 * @return command string
69 */
70 public String command() {
71 return command;
72 }
73
74 /**
Thomas Vachuska4bfccd542015-05-30 00:35:25 -070075 * Returns the step environment script path.
76 *
77 * @return env script path
78 */
79 public String env() {
80 return env;
81 }
82
83 /**
84 * Returns the step current working directory path.
85 *
86 * @return current working dir path
87 */
88 public String cwd() {
89 return cwd;
90 }
91
92 /**
Thomas Vachuskaf9c84362015-04-15 11:20:45 -070093 * Returns the enclosing group; null if none.
94 *
95 * @return enclosing group or null
96 */
97 public Group group() {
98 return group;
99 }
100
101
102 @Override
103 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -0700104 return name.hashCode();
Thomas Vachuskaf9c84362015-04-15 11:20:45 -0700105 }
106
107 @Override
108 public boolean equals(Object obj) {
109 if (this == obj) {
110 return true;
111 }
112 if (obj instanceof Step) {
113 final Step other = (Step) obj;
114 return Objects.equals(this.name, other.name);
115 }
116 return false;
117 }
118
119 @Override
120 public String toString() {
121 return MoreObjects.toStringHelper(this)
122 .add("name", name)
123 .add("command", command)
Thomas Vachuska4bfccd542015-05-30 00:35:25 -0700124 .add("env", env)
125 .add("cwd", cwd)
Thomas Vachuskaf9c84362015-04-15 11:20:45 -0700126 .add("group", group)
127 .toString();
128 }
129}