View Javadoc
1   /*
2    * Copyright 2008 FatWire Corporation. All Rights Reserved.
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   */
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   * test case for assetIdUtils
25   *
26   * @author Tony Field
27   * @since Mar 9, 2011
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 }