1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/**
* Copyright (c) 2009 Red Hat, Inc.
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* Red Hat trademarks are not licensed under GPLv2. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/
package org.fedoraproject.candlepin.resource;
import org.fedoraproject.candlepin.model.Consumer;
import org.fedoraproject.candlepin.model.ConsumerInfo;
import org.fedoraproject.candlepin.model.ConsumerType;
import org.fedoraproject.candlepin.model.ObjectFactory;
import org.fedoraproject.candlepin.model.TestUtil;
import org.fedoraproject.candlepin.resource.ConsumerResource;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* ConsumerResourceTest
* @version $Rev$
*/
public class ConsumerResourceTest {
@Test
public void testCreateConsumer() throws Exception {
String newname = "test-consumer-" + System.currentTimeMillis();
ConsumerResource capi = new ConsumerResource();
ConsumerInfo ci = new ConsumerInfo();
ci.setMetadataField("name", newname);
ci.setType(new ConsumerType("standard-system"));
capi.create(ci);
assertNotNull(ObjectFactory.get().lookupByFieldName(Consumer.class,
"name", newname));
}
@Test
public void testDelete() {
Consumer c = TestUtil.createConsumer();
String uuid = c.getUuid();
ConsumerResource capi = new ConsumerResource();
assertNotNull(ObjectFactory.get().lookupByUUID(c.getClass(), uuid));
capi.delete(uuid);
assertNull(ObjectFactory.get().lookupByUUID(c.getClass(), uuid));
}
@Test
public void testJSON() {
ClientConfig cc = new DefaultClientConfig();
Client c = Client.create(cc);
ConsumerInfo ci = new ConsumerInfo();
ci.setMetadataField("name", "jsontestname");
ci.setType(new ConsumerType("standard-system"));
WebResource res =
c.resource("http://localhost:8080/candlepin/consumer/");
Consumer rc = res.type("application/json").post(Consumer.class, ci);
assertNotNull(rc);
assertNotNull(rc.getUuid());
System.out.println(rc.getUuid());
// WebResource delres =
// c.resource("http://localhost:8080/candlepin/consumer/");
// delres.accept("application/json").delete(rc.getUuid());
//
// assertNull(ObjectFactory.get().lookupByUUID(c.getClass(), rc.getUuid()));
}
}
|