1   /*
2    * Copyright 2007 the original author or authors.
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  package net.sf.jdigg.requests;
17  
18  import java.util.List;
19  
20  import net.sf.jdigg.arguments.ListContainersArguments;
21  import net.sf.jdigg.beans.ContainerWithTopics;
22  import net.sf.jdigg.beans.Containers;
23  import net.sf.jdigg.exception.DiggException;
24  import net.sf.jdigg.exception.RequestException;
25  import net.sf.jdigg.exception.ResponseParserException;
26  
27  /**
28   * JUnit Test.
29   * @author Raymond H
30   * @author Philip May
31   * @since 1.0 M2
32   */
33  public class ListContainersRequestTest extends ListRequestTestCase {
34  
35      public ListContainersRequestTest() {
36      }
37  
38      public ListContainersRequestTest(String name) {
39          super(name);
40      }
41  
42      private void assertContainerWithTopics(ContainerWithTopics containerWithTopics) {
43          assertTrue(containerWithTopics.getName().length() > 0);
44          assertTrue(containerWithTopics.getShortName().length() > 0);
45          assertTrue(containerWithTopics.getTopicList().size() > 0);
46      }
47  
48      public void testAllContainers() throws RequestException, ResponseParserException, DiggException {
49          ListContainersArguments listContainersArguments = new ListContainersArguments("http://sf.net");
50  
51          ListContainersRequest listContainersRequest = new ListContainersRequest(getRequestConfig());
52          Containers result = listContainersRequest.allContainers(listContainersArguments);
53  
54          assertNotNull(result);
55          assertNotNull(result.getContainerWithTopicsList());
56          assertTrue(result.getContainerWithTopicsList().size() > 0);
57          // Currently 8 fixed container.
58          assertEquals(8, result.getContainerWithTopicsList().size());
59          assertContainerWithTopics((ContainerWithTopics) result.getContainerWithTopicsList().iterator().next());
60      }
61  
62      public void testSpecifiedContainer() throws RequestException, ResponseParserException, DiggException {
63          final String CONTAINER = "technology";
64  
65          ListContainersArguments listContainersArguments = new ListContainersArguments("http://sf.net");
66  
67          ListContainersRequest listContainersRequest = new ListContainersRequest(getRequestConfig());
68          Containers result = listContainersRequest.specifiedContainer(listContainersArguments, CONTAINER);
69  
70          assertNotNull(result);
71          List containerWithTopicsList = result.getContainerWithTopicsList();
72          assertNotNull(containerWithTopicsList);
73      }
74  
75      public void testDiggException() throws RequestException, ResponseParserException, DiggException {
76          ListContainersArguments listContainersArguments = new ListContainersArguments("http://sf.net");
77  
78          ListContainersRequest listContainersRequest = new ListContainersRequest(getRequestConfig());
79          try {
80              listContainersRequest.specifiedContainer(listContainersArguments, "xyz");
81              fail();
82          } catch (DiggException e) {
83              assertEquals(404, e.getDiggErrorCode());
84              assertNotNull(e.getDiggErrorMessage());
85              assertTrue(e.getDiggErrorMessage().length() > 0);
86          }
87  
88      }
89  
90      public void testRequestConfigNotNull() {
91          try {
92              new ListContainersRequest(null);
93              fail();
94          } catch (IllegalArgumentException e) {
95              // everything is all right!
96          }
97      }
98  
99  }