Sonar Fixes, Formatting
[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
23 package org.onap.aaf.cadi.wsse.test;
24
25 import org.junit.Test;
26 import org.onap.aaf.cadi.wsse.WSSEParser;
27
28 public class JU_WSSEParser {
29
30     @Test
31     public void test() {
32         @SuppressWarnings("unused")
33         WSSEParser wp = new WSSEParser();
34
35         // TODO: test the rest of this class
36 //        final BasicCred bc = new BasicCred() {
37 //            private String user;
38 //            private byte[] password;
39 //
40 //            public void setUser(String user) { this.user = user; }
41 //            public void setCred(byte[] passwd) { this.password = passwd; }
42 //            public String getUser() { return user; }
43 //            public byte[] getCred() { return password; }
44 //        };
45
46 //        FileInputStream fis;
47 //        fis = new FileInputStream("test/example.xml");
48 //        BufferedServletInputStream is = new BufferedServletInputStream(fis);
49 //        try {
50 //            is.mark(1536);
51 //            try {
52 //                assertNull(wp.parse(bc, is));
53 //            } finally {
54 //                is.reset();
55 //                assertEquals(814,is.buffered());
56 //            }
57 //            String password = new String(bc.getCred());
58 //            System.out.println("CadiWrap credentials are: " + bc.getUser() + ", " + password);
59 //            assertEquals("some_user", bc.getUser());
60 //            assertEquals("some_password", password);
61 //
62 //        } finally {
63 //            fis.close();
64 //        }
65 //
66 //        // CBUS (larger)
67 //        fis = new FileInputStream("test/CBUSevent.xml");
68 //        is = new BufferedServletInputStream(fis);
69 //        try {
70 //            is.mark(1536);
71 //            try {
72 //                assertNull(wp.parse(bc, is));
73 //            } finally {
74 //                is.reset();
75 //                assertEquals(667,is.buffered());
76 //            }
77 //            String password = new String(bc.getCred());
78 //            System.out.println("CadiWrap credentials are: " + bc.getUser() + ", " + password);
79 //            assertEquals("none", bc.getUser());
80 //            assertEquals("none", password);
81 //
82 //        } finally {
83 //            fis.close();
84 //        }
85 //
86 //        // Closed Stream
87 //        fis = new FileInputStream("test/example.xml");
88 //        fis.close();
89 //        bc.setCred(null);
90 //        bc.setUser(null);
91 //        XMLStreamException ex = wp.parse(bc, fis);
92 //        assertNotNull(ex);
93 //        assertNull(bc.getUser());
94 //        assertNull(bc.getCred());
95 //
96 //
97 //        fis = new FileInputStream("test/exampleNoSecurity.xml");
98 //        try {
99 //            bc.setCred(null);
100 //            bc.setUser(null);
101 //            assertNull(wp.parse(bc, fis));
102 //            assertNull(bc.getUser());
103 //            assertNull(bc.getCred());
104 //        } finally {
105 //            fis.close();
106 //        }
107 //
108 //        fis = new FileInputStream("test/exampleBad1.xml");
109 //        try {
110 //            bc.setCred(null);
111 //            bc.setUser(null);
112 //            assertNull(wp.parse(bc, fis));
113 //            assertNull(bc.getUser());
114 //            assertNull(bc.getCred());
115 //        } finally {
116 //            fis.close();
117 //        }
118 //
119 //        XMLStreamException e = wp.parse(bc, new ByteArrayInputStream("Not XML".getBytes())); // empty
120 //        assertNotNull(e);
121 //
122 //        e = wp.parse(bc, new ByteArrayInputStream("".getBytes())); // empty
123 //        assertNotNull(e);
124 //
125 //
126 //        long start, count = 0L;
127 //        int iter = 30000;
128 //        File f = new File("test/CBUSevent.xml");
129 //        fis = new FileInputStream(f);
130 //        is = new BufferedServletInputStream(fis);
131 //        is.mark(0);
132 //        try {
133 //            while (is.read()>=0);
134 //        } finally {
135 //            fis.close();
136 //        }
137 //
138 //        for (int i=0;i<iter;++i) {
139 //            start = System.nanoTime();
140 //            is.reset();
141 //            try {
142 //                assertNull(wp.parse(bc, is));
143 //            } finally {
144 //                count += System.nanoTime()-start;
145 //            }
146 //        }
147 //        float ms = count/1000000f;
148 //        System.out.println("Executed " + iter + " WSSE reads from Memory Stream in " + ms + "ms.  " + ms/iter + "ms per trans");
149 //
150 //        // SPECIFIC ISSUES
151 //
152 //        fis = new FileInputStream("test/error2013_04_23.xml");
153 //        try {
154 //            bc.setCred(null);
155 //            bc.setUser(null);
156 //            assertNull(wp.parse(bc, fis));
157 //            assertNull(bc.getUser());
158 //            assertNull(bc.getCred());
159 //        } finally {
160 //            fis.close();
161 //        }
162     }
163
164 }