package customer;

import org.junit.Test;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import customer.model.Customer;
import customer.util.EncryptUtil;


public class EncryptTest {
	
	
	@Test
	public void testEncrypt() throws Exception {
		final String plaintext = "abcdefgh";
		final String testKey = "+rHvI/C6AXVkBgqal+okun5IqECz1RjrsJNEOm7o5x8=";
		
		final String encrypted = EncryptUtil.encrypt(testKey, plaintext);
		
		System.out.println("encrypted: " + encrypted);
		
		final String decrypted = EncryptUtil.decrypt(testKey, encrypted);
		
		System.out.println("decrypted: " + decrypted);
		
		assert(plaintext.equals(decrypted));
		
	}
	
	@Test
	public void testMarshalFromJson() throws Exception {
		final String id = "asdgadsfads";
		
		final ObjectMapper mapper = new ObjectMapper();
		
		// construct a json string with the above properties
		
		final StringBuilder myJsonStr = new StringBuilder();
		
		myJsonStr.append("{");
		myJsonStr.append("\"customerId\":\"").append(id).append("\",");
		myJsonStr.append("\"email\":").append("\"my@email.com\"").append(",");
		myJsonStr.append("\"firstName\":").append("\"John\"").append(",");
		myJsonStr.append("\"lastName\":").append("\"Smith\"").append(",");
		myJsonStr.append("\"imageUrl\":").append("\"/image/myimage.jpg\"").append(",");
		myJsonStr.append("\"username\":").append("\"user1\"").append(",");
		myJsonStr.append("}");
		
		final String myJson = myJsonStr.toString();
		System.out.println("My JSON String:" + myJson);
		
		// marshall json to Customer object
		
		final Customer inv = mapper.readValue(myJson, Customer.class);
		
		// make sure all the properties match up
		assert(inv.getCustomerId().equals(id));
		assert(inv.getFirstName().equals("John"));
		assert(inv.getLastName().equals("Smith"));
		assert(inv.getImageUrl().equals("/image/myimage.jpg"));
		assert(inv.getUsername().equals("user1"));
		assert(inv.getEmail().equals("my@email.com"));
		
		
	}
}
@@ -699,1300 +699,5 @@
 %0A%09%7D%0A
-%09%0A%09@Test%0A%09public void testMarshalFromJson() throws Exception %7B%0A%09%09final String id = %22asdgadsfads%22;%0A%09%09%0A%09%09final ObjectMapper mapper = new ObjectMapper();%0A%09%09%0A%09%09// construct a json string with the above properties%0A%09%09%0A%09%09final StringBuilder myJsonStr = new StringBuilder();%0A%09%09%0A%09%09myJsonStr.append(%22%7B%22);%0A%09%09myJsonStr.append(%22%5C%22customerId%5C%22:%5C%22%22).append(id).append(%22%5C%22,%22);%0A%09%09myJsonStr.append(%22%5C%22email%5C%22:%22).append(%22%5C%22my@email.com%5C%22%22).append(%22,%22);%0A%09%09myJsonStr.append(%22%5C%22firstName%5C%22:%22).append(%22%5C%22John%5C%22%22).append(%22,%22);%0A%09%09myJsonStr.append(%22%5C%22lastName%5C%22:%22).append(%22%5C%22Smith%5C%22%22).append(%22,%22);%0A%09%09myJsonStr.append(%22%5C%22imageUrl%5C%22:%22).append(%22%5C%22/image/myimage.jpg%5C%22%22).append(%22,%22);%0A%09%09myJsonStr.append(%22%5C%22username%5C%22:%22).append(%22%5C%22user1%5C%22%22).append(%22,%22);%0A%09%09myJsonStr.append(%22%7D%22);%0A%09%09%0A%09%09final String myJson = myJsonStr.toString();%0A%09%09System.out.println(%22My JSON String:%22 + myJson);%0A%09%09%0A%09%09// marshall json to Customer object%0A%09%09%0A%09%09final Customer inv = mapper.readValue(myJson, Customer.class);%0A%09%09%0A%09%09// make sure all the properties match up%0A%09%09assert(inv.getCustomerId().equals(id));%0A%09%09assert(inv.getFirstName().equals(%22John%22));%0A%09%09assert(inv.getLastName().equals(%22Smith%22));%0A%09%09assert(inv.getImageUrl().equals(%22/image/myimage.jpg%22));%0A%09%09assert(inv.getUsername().equals(%22user1%22));%0A%09%09assert(inv.getEmail().equals(%22my@email.com%22));%0A%09%09%0A%09%09%0A%09%7D%0A
 %7D

fix bug in tests