1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.facade.assetapi;
18
19 import com.fatwire.assetapi.data.AssetId;
20 import junit.framework.Assert;
21 import junit.framework.TestCase;
22
23
24
25
26
27
28
29 public final class AssetIdUtilsTest extends TestCase {
30 public void testFromString() {
31 AssetId id = AssetIdUtils.fromString("article:123");
32 Assert.assertEquals("123", Long.toString(id.getId()));
33 Assert.assertEquals("article", id.getType());
34
35 try {
36 AssetIdUtils.fromString(null);
37 Assert.fail("Successfully parsed garbage");
38 } catch (IllegalArgumentException e) {
39 Assert.assertTrue(true);
40 } catch (Throwable t) {
41 Assert.fail("bad data did not return the right exception for null input: " + t);
42 }
43
44 try {
45 AssetIdUtils.fromString("foo");
46 Assert.fail("Successfully parsed garbage");
47 } catch (IllegalArgumentException e) {
48 Assert.assertTrue(true);
49 } catch (Throwable t) {
50 Assert.fail("bad data did not return the right exception for foo input: " + t);
51 }
52
53 try {
54 AssetIdUtils.fromString("foo:");
55 Assert.fail("Successfully parsed garbage");
56 } catch (IllegalArgumentException e) {
57 Assert.assertTrue(true);
58 } catch (Throwable t) {
59 Assert.fail("bad data did not return the right exception for foo: input: " + t);
60 }
61
62 try {
63 AssetIdUtils.fromString("foo:bar");
64 Assert.fail("Successfully parsed garbage");
65 } catch (IllegalArgumentException e) {
66 Assert.assertTrue(true);
67 } catch (Throwable t) {
68 Assert.fail("bad data did not return the right exception for foo:bar input: " + t);
69 }
70
71 try {
72 AssetIdUtils.fromString("foo:");
73 Assert.fail("Successfully parsed garbage");
74 } catch (IllegalArgumentException e) {
75 Assert.assertTrue(true);
76 } catch (Throwable t) {
77 Assert.fail("bad data did not return the right exception for foo: input: " + t);
78 }
79
80 try {
81 AssetIdUtils.fromString(":123");
82 Assert.fail("Successfully parsed garbage");
83 } catch (IllegalArgumentException e) {
84 Assert.assertTrue(true);
85 } catch (Throwable t) {
86 Assert.fail("bad data did not return the right exception for :123 input: " + t);
87 }
88
89 try {
90 AssetIdUtils.fromString(":");
91 Assert.fail("Successfully parsed garbage");
92 } catch (IllegalArgumentException e) {
93 Assert.assertTrue(true);
94 } catch (Throwable t) {
95 Assert.fail("bad data did not return the right exception for : input: " + t);
96 }
97
98 }
99
100 }