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