/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache license, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.internna.iwebmvc.core.crypto;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.internna.iwebmvc.core.crypto.impl.DES3CiphererDecipherer;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import stubs.crypto.ContainerEntity;
import static org.junit.Assert.*;
/**
*
* @author Jose Noheda
* @since 1.0
*/
public class AbstractCiphererTest {
private static AbstractCipherer cipherer;
private ContainerEntity e;
@BeforeClass
public static void setUpClass() throws Exception {
DES3CiphererDecipherer des3 = new DES3CiphererDecipherer();
des3.init();
cipherer = des3;
}
@Before
public void setUp() {
e = new ContainerEntity(cipherer);
e.setName("xxxx");
e.setSurname("yyyyy");
Map<String, ContainerEntity> m = new HashMap<String, ContainerEntity>();
ContainerEntity cm = new ContainerEntity(cipherer);
cm.setName("zzzzz");
cm.setSurname("yyyyy");
m.put("a", cm);
e.setContainedMap(m);
List<ContainerEntity> l = new ArrayList<ContainerEntity>(1);
ContainerEntity cl = new ContainerEntity(cipherer);
cl.setName("ooooo");
cl.setSurname("yyyyy");
l.add(cl);
e.setContainedList(l);
Set<ContainerEntity> s = new HashSet<ContainerEntity>(1);
ContainerEntity cs = new ContainerEntity(cipherer);
cs.setName("uuuuu");
cs.setSurname("yyyyy");
s.add(cs);
e.setContainedSet(s);
}
@Test
public void encrypt() {
ContainerEntity x = cipherer.encrypt(e);
assertEquals("Surname is not encrypted", "yyyyy", x.getSurname());
assertFalse("Name is encrypted", "xxxx".equals(x.getSurname()));
assertEquals("Surname is not encrypted in map", "yyyyy", x.getContainedMap().get("a").getSurname());
assertFalse("Name is encrypted in map", "zzzzz".equals(x.getContainedMap().get("a").getSurname()));
assertEquals("Surname is not encrypted in list", "yyyyy", x.getContainedList().get(0).getSurname());
assertFalse("Name is encrypted in list", "ooooo".equals(x.getContainedList().get(0).getSurname()));
assertEquals("Surname is not encrypted in set", "yyyyy", x.getContainedSet().iterator().next().getSurname());
assertFalse("Name is encrypted in set", "uuuuu".equals(x.getContainedSet().iterator().next().getSurname()));
}
}