Initial import.
[clinton/mirror/jspi/.git] / jspi / src / main / java / de / lohndirekt / print / IppPrintServiceTest.java
1 /**
2 * Copyright (C) 2003 <a href="http://www.lohndirekt.de/">lohndirekt.de</a>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19 package de.lohndirekt.print;
20
21 import java.net.URI;
22 import java.util.Arrays;
23 import java.util.List;
24 import java.util.logging.Logger;
25
26 import javax.print.PrintService;
27 import javax.print.attribute.Attribute;
28
29 import junit.framework.TestCase;
30 import de.lohndirekt.print.attribute.IppAttributeName;
31 import de.lohndirekt.print.test.IppRequestTestImpl;
32
33 /**
34 * @author bpusch
35 *
36 */
37 public class IppPrintServiceTest extends TestCase {
38
39 PrintService service;
40 Logger log;
41
42 /**
43 * Constructor for IppPrintServiceTest.
44 * @param arg0
45 */
46 public IppPrintServiceTest(String arg0) {
47 super(arg0);
48 }
49
50 /*
51 * @see TestCase#setUp()
52 */
53 protected void setUp() throws Exception {
54 super.setUp();
55 System.setProperty(IppRequestFactory.IPP_REQUEST_IMPL_KEY, IppRequestTestImpl.class.getName());
56 IppPrintServiceLookup lookup = new IppPrintServiceLookup(new URI("http://127.0.0.1"), "", "");
57 PrintService[] services = lookup.getPrintServices();
58 this.service = services[0];
59 this.log = Logger.getLogger(this.getName());
60 }
61
62 public void testGetSupportedAttributeCategories() {
63 Class[] categories = this.service.getSupportedAttributeCategories();
64 assertNotNull(categories);
65 List cats = Arrays.asList(categories);
66 assertTrue(cats.contains(IppAttributeName.JOB_PRIORIY.getCategory()));
67 assertTrue(cats.contains(IppAttributeName.JOB_HOLD_UNTIL.getCategory()));
68 assertTrue(cats.contains(IppAttributeName.JOB_SHEETS.getCategory()));
69 assertTrue(cats.contains(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING.getCategory()));
70 assertTrue(cats.contains(IppAttributeName.COPIES.getCategory()));
71 assertTrue(cats.contains(IppAttributeName.FINISHINGS.getCategory()));
72 assertTrue(cats.contains(IppAttributeName.SIDES.getCategory()));
73 assertTrue(cats.contains(IppAttributeName.NUMBER_UP.getCategory()));
74 assertTrue(cats.contains(IppAttributeName.ORIENTATION_REQUESTED.getCategory()));
75 assertTrue(cats.contains(IppAttributeName.MEDIA.getCategory()));
76 assertTrue(cats.contains(IppAttributeName.COMPRESSION.getCategory()));
77 assertTrue(cats.contains(IppAttributeName.JOB_K_OCTETS.getCategory()));
78 assertTrue(cats.contains(IppAttributeName.JOB_IMPRESSIONS.getCategory()));
79 assertTrue(cats.contains(IppAttributeName.JOB_MEDIA_SHEETS.getCategory()));
80 }
81
82 public void testIsAttributeCategorySupported() {
83 Class category = IppAttributeName.JOB_SHEETS.getCategory();
84 boolean supported = this.service.isAttributeCategorySupported(category);
85 assertEquals(Arrays.asList(this.service.getSupportedAttributeCategories()).contains(category), supported);
86
87 }
88
89 public void testGetSupportedAttributeValues() {
90 Class category = IppAttributeName.MEDIA.getCategory();
91 Attribute[] attrs = (Attribute[]) this.service.getSupportedAttributeValues(category, null, null);
92 assertEquals("Should be 2 media-supported attributes", 2, attrs.length);
93 for (int j = 0; j < attrs.length; j++) {
94 Attribute attribute = attrs[j];
95 assertEquals(IppAttributeName.MEDIA_SUPPORTED.getCategory(), attribute.getCategory());
96 }
97 category = IppAttributeName.COMPRESSION.getCategory();
98 attrs = (Attribute[]) this.service.getSupportedAttributeValues(category, null, null);
99 for (int j = 0; j < attrs.length; j++) {
100 Attribute attribute = attrs[j];
101 assertEquals(IppAttributeName.COMPRESSION_SUPORTED.getCategory(), attribute.getCategory());
102 }
103 category = IppAttributeName.JOB_PRIORIY.getCategory();
104 attrs = (Attribute[]) this.service.getSupportedAttributeValues(category, null, null);
105 assertEquals("Should be 1 job-priority-supported attribute", 1, attrs.length);
106 for (int j = 0; j < attrs.length; j++) {
107 Attribute attribute = attrs[j];
108 assertEquals(IppAttributeName.JOB_PRIORIY_SUPPORTED.getCategory(), attribute.getCategory());
109 }
110 category = IppAttributeName.SIDES.getCategory();
111 attrs = (Attribute[]) this.service.getSupportedAttributeValues(category, null, null);
112 assertEquals("Should be 2 sides-supported attributes", 2, attrs.length);
113 for (int j = 0; j < attrs.length; j++) {
114 Attribute attribute = attrs[j];
115 assertEquals(IppAttributeName.SIDES_SUPPORTED.getCategory(), attribute.getCategory());
116 }
117
118 }
119
120 }