01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Igor A. Pyankov
19: * @version $Revision: 1.2 $
20: */package javax.print;
21:
22: import java.net.URI;
23: import java.net.URISyntaxException;
24: import java.util.Locale;
25:
26: import javax.print.attribute.Attribute;
27: import javax.print.attribute.AttributeSet;
28: import javax.print.attribute.HashAttributeSet;
29: import javax.print.attribute.standard.Destination;
30: import javax.print.attribute.standard.DocumentName;
31: import javax.print.attribute.standard.Finishings;
32: import javax.print.attribute.standard.JobName;
33: import javax.print.attribute.standard.MediaSizeName;
34: import javax.print.attribute.standard.RequestingUserName;
35:
36: import junit.framework.TestCase;
37:
38: public class GetUnsupportedAttributesTest extends TestCase {
39: public void testIsAttributeValueSupported() throws Exception {
40: System.out
41: .println("============= START GetUnsupportedAttributesTest ================");
42:
43: PrintService[] services;
44: DocFlavor[] flavors = new DocFlavor[] {
45: DocFlavor.INPUT_STREAM.GIF,
46: DocFlavor.INPUT_STREAM.POSTSCRIPT,
47: DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII };
48:
49: services = PrintServiceLookup.lookupPrintServices(null, null);
50: TestUtil.checkServices(services);
51: if (services.length > 0) {
52: for (int i = 0, ii = services.length; i < ii; i++) {
53: System.out.println("----------- "
54: + services[i].getName() + "----------");
55:
56: URI uri = null;
57: try {
58: uri = new URI("file:///c:/no/such/dir/print.out");
59: //uri = File.createTempFile("xxx", null).toURI();
60: } catch (URISyntaxException e) {
61: fail();
62: }
63:
64: AttributeSet attrs = new HashAttributeSet();
65: attrs.add(Finishings.EDGE_STITCH);
66: attrs.add(MediaSizeName.JAPANESE_DOUBLE_POSTCARD);
67: attrs.add(new Destination(uri));
68: attrs.add(new DocumentName("Doc X", Locale.US));
69: attrs.add(new JobName("Job Y", Locale.US));
70: attrs.add(new RequestingUserName("User Z", Locale.US));
71:
72: for (int j = 0; j < flavors.length; j++) {
73: if (services[i].isDocFlavorSupported(flavors[j])) {
74: AttributeSet aset = services[i]
75: .getUnsupportedAttributes(flavors[j],
76: attrs);
77: if (aset == null) {
78: fail("At least one attribute is unsupported");
79: }
80: if (aset != null) {
81: Attribute[] aarr = aset.toArray();
82: System.out
83: .println("Usupported attributes fo DocFlavor "
84: + flavors[j]);
85: for (int k = 0, kk = aarr.length; k < kk; k++) {
86: System.out.println("\t" + aarr[k]);
87: }
88: }
89: }
90: }
91: }
92: }
93:
94: System.out
95: .println("============= END GetUnsupportedAttributesTest ================");
96: }
97:
98: }
|