Mass removal of all Tabs (Style Warnings)
[aaf/authz.git] / cadi / core / src / test / java / org / onap / aaf / cadi / wsse / test / JU_WSSEParser.java
1 /*******************************************************************************
2 * ============LICENSE_START====================================================
3 * * org.onap.aaf
4 * * ===========================================================================
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * * ===========================================================================
7 * * Licensed under the Apache License, Version 2.0 (the "License");
8 * * you may not use this file except in compliance with the License.
9 * * You may obtain a copy of the License at
10 * * 
11 *  *      http://www.apache.org/licenses/LICENSE-2.0
12 * * 
13 *  * Unless required by applicable law or agreed to in writing, software
14 * * distributed under the License is distributed on an "AS IS" BASIS,
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * * See the License for the specific language governing permissions and
17 * * limitations under the License.
18 * * ============LICENSE_END====================================================
19 * *
20 * *
21 ******************************************************************************/
22 package org.onap.aaf.cadi.wsse.test;
23
24 import org.junit.Test;
25 import org.onap.aaf.cadi.wsse.WSSEParser;
26
27 public class JU_WSSEParser {
28
29     @Test
30     public void test() {
31         @SuppressWarnings("unused")
32         WSSEParser wp = new WSSEParser();
33
34         // TODO: test the rest of this class
35 //        final BasicCred bc = new BasicCred() {
36 //            private String user;
37 //            private byte[] password;
38 //
39 //            public void setUser(String user) { this.user = user; } 
40 //            public void setCred(byte[] passwd) { this.password = passwd; }
41 //            public String getUser() { return user; } 
42 //            public byte[] getCred() { return password; }
43 //        };
44
45 //        FileInputStream fis;
46 //        fis = new FileInputStream("test/example.xml");
47 //        BufferedServletInputStream is = new BufferedServletInputStream(fis);
48 //        try {
49 //            is.mark(1536);
50 //            try {
51 //                assertNull(wp.parse(bc, is));
52 //            } finally {
53 //                is.reset();
54 //                assertEquals(814,is.buffered());
55 //            }
56 //            String password = new String(bc.getCred());
57 //            System.out.println("CadiWrap credentials are: " + bc.getUser() + ", " + password);
58 //            assertEquals("some_user", bc.getUser());
59 //            assertEquals("some_password", password);
60 //            
61 //        } finally {
62 //            fis.close();
63 //        }
64 //
65 //        // CBUS (larger)
66 //        fis = new FileInputStream("test/CBUSevent.xml");
67 //        is = new BufferedServletInputStream(fis);
68 //        try {
69 //            is.mark(1536);
70 //            try {
71 //                assertNull(wp.parse(bc, is));
72 //            } finally {
73 //                is.reset();
74 //                assertEquals(667,is.buffered());
75 //            }
76 //            String password = new String(bc.getCred());
77 //            System.out.println("CadiWrap credentials are: " + bc.getUser() + ", " + password);
78 //            assertEquals("none", bc.getUser());
79 //            assertEquals("none", password);
80 //            
81 //        } finally {
82 //            fis.close();
83 //        }
84 //
85 //        // Closed Stream
86 //        fis = new FileInputStream("test/example.xml");
87 //        fis.close();
88 //        bc.setCred(null);
89 //        bc.setUser(null);
90 //        XMLStreamException ex = wp.parse(bc, fis);
91 //        assertNotNull(ex);
92 //        assertNull(bc.getUser());
93 //        assertNull(bc.getCred());
94 //
95 //
96 //        fis = new FileInputStream("test/exampleNoSecurity.xml");
97 //        try {
98 //            bc.setCred(null);
99 //            bc.setUser(null);
100 //            assertNull(wp.parse(bc, fis));
101 //            assertNull(bc.getUser());
102 //            assertNull(bc.getCred());
103 //        } finally {
104 //            fis.close();
105 //        }
106 //
107 //        fis = new FileInputStream("test/exampleBad1.xml");
108 //        try {
109 //            bc.setCred(null);
110 //            bc.setUser(null);
111 //            assertNull(wp.parse(bc, fis));
112 //            assertNull(bc.getUser());
113 //            assertNull(bc.getCred());
114 //        } finally {
115 //            fis.close();
116 //        }
117 //
118 //        XMLStreamException e = wp.parse(bc, new ByteArrayInputStream("Not XML".getBytes())); // empty
119 //        assertNotNull(e);
120 //
121 //        e = wp.parse(bc, new ByteArrayInputStream("".getBytes())); // empty
122 //        assertNotNull(e);
123 //        
124 //        
125 //        long start, count = 0L;
126 //        int iter = 30000;
127 //        File f = new File("test/CBUSevent.xml");
128 //        fis = new FileInputStream(f);
129 //        is = new BufferedServletInputStream(fis);
130 //        is.mark(0);
131 //        try {
132 //            while(is.read()>=0);
133 //        } finally {
134 //            fis.close();
135 //        }
136 //
137 //        for(int i=0;i<iter;++i) {
138 //            start = System.nanoTime();
139 //            is.reset();
140 //            try {
141 //                assertNull(wp.parse(bc, is));
142 //            } finally {
143 //                count += System.nanoTime()-start;
144 //            }
145 //        }
146 //        float ms = count/1000000f;
147 //        System.out.println("Executed " + iter + " WSSE reads from Memory Stream in " + ms + "ms.  " + ms/iter + "ms per trans");
148 //        
149 //        // SPECIFIC ISSUES
150 //        
151 //        fis = new FileInputStream("test/error2013_04_23.xml");
152 //        try {
153 //            bc.setCred(null);
154 //            bc.setUser(null);
155 //            assertNull(wp.parse(bc, fis));
156 //            assertNull(bc.getUser());
157 //            assertNull(bc.getCred());
158 //        } finally {
159 //            fis.close();
160 //        }
161     }
162
163 }