File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\test\java\hudson\slaves\NodeListTest.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.slaves;
25
26
27 import jenkins.model.Jenkins;
28 import junit.framework.TestCase;
29 import hudson.model.Node;
30 import hudson.model.TaskListener;
31 import hudson.model.Computer;
32 import hudson.model.TopLevelItem;
33 import hudson.XmlFile;
34 import hudson.Launcher;
35 import hudson.FilePath;
36 import hudson.model.labels.LabelAtom;
37 import hudson.util.ClockDifference;
38 import hudson.util.DescribableList;
39
40 import java.io.File;
41 import java.io.IOException;
42 import java.util.Random;
43 import java.util.Set;
44
45 import org.apache.commons.io.FileUtils;
46
47 /**
48 * @author Kohsuke Kawaguchi
49 */
50 public class NodeListTest extends TestCase {
51 static class DummyNode extends Node {
52 String nodeName = Long.toString(new Random().nextLong());
53 public String getNodeName() {
54 return nodeName;
55 }
56
57 public void setNodeName(String name) {
58 throw new UnsupportedOperationException();
59 }
60
61 public String getNodeDescription() {
62 throw new UnsupportedOperationException();
63 }
64
65 public Launcher createLauncher(TaskListener listener) {
66 throw new UnsupportedOperationException();
67 }
68
69 public int getNumExecutors() {
70 throw new UnsupportedOperationException();
71 }
72
73 public Mode getMode() {
74 throw new UnsupportedOperationException();
75 }
76
77 public Computer createComputer() {
78 throw new UnsupportedOperationException();
79 }
80
81 public Set<LabelAtom> getAssignedLabels() {
82 throw new UnsupportedOperationException();
83 }
84
85 public String getLabelString() {
86 throw new UnsupportedOperationException();
87 }
88
89 public void setLabelString(String labelString) throws IOException {
90 throw new UnsupportedOperationException();
91 }
92
93 public FilePath getWorkspaceFor(TopLevelItem item) {
94 throw new UnsupportedOperationException();
95 }
96
97 public FilePath getRootPath() {
98 throw new UnsupportedOperationException();
99 }
100
101 public ClockDifference getClockDifference() throws IOException, InterruptedException {
102 throw new UnsupportedOperationException();
103 }
104
105 public NodeDescriptor getDescriptor() {
106 throw new UnsupportedOperationException();
107 }
108
109 @Override
110 public DescribableList<NodeProperty<?>, NodePropertyDescriptor> getNodeProperties() {
111 throw new UnsupportedOperationException();
112 }
113 }
114 static class EphemeralNode extends DummyNode implements hudson.slaves.EphemeralNode {
115 public Node asNode() {
116 return this;
117 }
118 }
119
120 public void testSerialization() throws Exception {
121 NodeList nl = new NodeList(new DummyNode(), new EphemeralNode());
122
123 File tmp = File.createTempFile("test","test");
124 try {
125 XmlFile x = new XmlFile(Jenkins.XSTREAM, tmp);
126 x.write(nl);
127
128 String xml = FileUtils.readFileToString(tmp);
129 System.out.println(xml);
130 assertEquals(6,xml.split("\n").length);
131
132 NodeList back = (NodeList)x.read();
133
134 assertEquals(1,back.size());
135 assertEquals(DummyNode.class,back.get(0).getClass());
136 } finally {
137 tmp.delete();
138 }
139 }
140 }
141