1 /*******************************************************************************
2 * ============LICENSE_START====================================================
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
11 * * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
21 ******************************************************************************/
22 package org.onap.aaf.cadi.wsse.test;
24 import static junit.framework.Assert.assertEquals;
25 import static junit.framework.Assert.assertNotNull;
26 import static junit.framework.Assert.assertNull;
28 import java.io.ByteArrayInputStream;
30 import java.io.FileInputStream;
32 import javax.xml.stream.XMLStreamException;
34 import org.junit.Test;
35 import org.onap.aaf.cadi.BasicCred;
36 import org.onap.aaf.cadi.BufferedServletInputStream;
37 import org.onap.aaf.cadi.wsse.WSSEParser;
39 public class JU_WSSE_Read {
42 // public void test() {
44 // final BasicCred bc = new BasicCred() {
46 // private String user;
47 // private byte[] password;
49 // public void setUser(String user) {
53 // public void setCred(byte[] passwd) {
54 // this.password = passwd;
57 // public String getUser() {
61 // public byte[] getCred() {
66 // WSSEParser wp = new WSSEParser();
68 // FileInputStream fis;
69 // fis = new FileInputStream("test/example.xml");
70 // BufferedServletInputStream is = new BufferedServletInputStream(fis);
74 // assertNull(wp.parse(bc, is));
77 // assertEquals(814,is.buffered());
79 // String password = new String(bc.getCred());
80 // System.out.println("CadiWrap credentials are: " + bc.getUser() + ", " + password);
81 // assertEquals("some_user", bc.getUser());
82 // assertEquals("some_password", password);
89 // fis = new FileInputStream("test/CBUSevent.xml");
90 // is = new BufferedServletInputStream(fis);
94 // assertNull(wp.parse(bc, is));
97 // assertEquals(667,is.buffered());
99 // String password = new String(bc.getCred());
100 // System.out.println("CadiWrap credentials are: " + bc.getUser() + ", " + password);
101 // assertEquals("none", bc.getUser());
102 // assertEquals("none", password);
109 // fis = new FileInputStream("test/example.xml");
113 // XMLStreamException ex = wp.parse(bc, fis);
114 // assertNotNull(ex);
115 // assertNull(bc.getUser());
116 // assertNull(bc.getCred());
119 // fis = new FileInputStream("test/exampleNoSecurity.xml");
123 // assertNull(wp.parse(bc, fis));
124 // assertNull(bc.getUser());
125 // assertNull(bc.getCred());
130 // fis = new FileInputStream("test/exampleBad1.xml");
134 // assertNull(wp.parse(bc, fis));
135 // assertNull(bc.getUser());
136 // assertNull(bc.getCred());
141 // XMLStreamException e = wp.parse(bc, new ByteArrayInputStream("Not XML".getBytes())); // empty
144 // e = wp.parse(bc, new ByteArrayInputStream("".getBytes())); // empty
148 // long start, count = 0L;
150 // File f = new File("test/CBUSevent.xml");
151 // fis = new FileInputStream(f);
152 // is = new BufferedServletInputStream(fis);
155 // while(is.read()>=0);
160 // for(int i=0;i<iter;++i) {
161 // start = System.nanoTime();
164 // assertNull(wp.parse(bc, is));
166 // count += System.nanoTime()-start;
169 // float ms = count/1000000f;
170 // System.out.println("Executed " + iter + " WSSE reads from Memory Stream in " + ms + "ms. " + ms/iter + "ms per trans");
172 // // SPECIFIC ISSUES
174 // fis = new FileInputStream("test/error2013_04_23.xml");
178 // assertNull(wp.parse(bc, fis));
179 // assertNull(bc.getUser());
180 // assertNull(bc.getCred());
184 // } catch(Exception e) {
185 // e.printStackTrace(System.err);