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  
21  import junit.framework.Assert;
22  import junit.framework.TestCase;
23  
24  /**
25   * test case for assetIdUtils
26   *
27   * @author Tony Field
28   * @since Mar 9, 2011
29   */
30  public final class AssetIdUtilsTest extends TestCase {
31      public void testFromString() {
32          AssetId id = AssetIdUtils.fromString("article:123");
33          Assert.assertEquals("123", Long.toString(id.getId()));
34          Assert.assertEquals("article", id.getType());
35  
36          try {
37              AssetIdUtils.fromString(null);
38              Assert.fail("Successfully parsed garbage");
39          } catch (IllegalArgumentException e) {
40              Assert.assertTrue(true);
41          } catch (Throwable t) {
42              Assert.fail("bad data did not return the right exception for null input: " + t);
43          }
44  
45          try {
46              AssetIdUtils.fromString("foo");
47              Assert.fail("Successfully parsed garbage");
48          } catch (IllegalArgumentException e) {
49              Assert.assertTrue(true);
50          } catch (Throwable t) {
51              Assert.fail("bad data did not return the right exception for foo input: " + t);
52          }
53  
54          try {
55              AssetIdUtils.fromString("foo:");
56              Assert.fail("Successfully parsed garbage");
57          } catch (IllegalArgumentException e) {
58              Assert.assertTrue(true);
59          } catch (Throwable t) {
60              Assert.fail("bad data did not return the right exception for foo: input: " + t);
61          }
62  
63          try {
64              AssetIdUtils.fromString("foo:bar");
65              Assert.fail("Successfully parsed garbage");
66          } catch (IllegalArgumentException e) {
67              Assert.assertTrue(true);
68          } catch (Throwable t) {
69              Assert.fail("bad data did not return the right exception for foo:bar input: " + t);
70          }
71  
72          try {
73              AssetIdUtils.fromString("foo:");
74              Assert.fail("Successfully parsed garbage");
75          } catch (IllegalArgumentException e) {
76              Assert.assertTrue(true);
77          } catch (Throwable t) {
78              Assert.fail("bad data did not return the right exception for foo: input: " + t);
79          }
80  
81          try {
82              AssetIdUtils.fromString(":123");
83              Assert.fail("Successfully parsed garbage");
84          } catch (IllegalArgumentException e) {
85              Assert.assertTrue(true);
86          } catch (Throwable t) {
87              Assert.fail("bad data did not return the right exception for :123 input: " + t);
88          }
89  
90          try {
91              AssetIdUtils.fromString(":");
92              Assert.fail("Successfully parsed garbage");
93          } catch (IllegalArgumentException e) {
94              Assert.assertTrue(true);
95          } catch (Throwable t) {
96              Assert.fail("bad data did not return the right exception for : input: " + t);
97          }
98  
99      }
100 
101 }