/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache license, Version 2.0 (the "License");
* you may not use tanImages 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.model.core;
import java.util.Date;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.internna.iwebmvc.model.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author Jose Noheda
* @since 1.0
*/
public class ImageTest {
private static EntityManagerFactory factory;
private static EntityManager entityManager;
private Image anImage;
@BeforeClass
public static void setUpClass() throws Exception {
factory = Persistence.createEntityManagerFactory("MODEL");
}
@Before
public void init() {
anImage = new Image();
anImage.setCreated(new Date());
anImage.setUri("/tmp/img1.gif");
anImage.setMimeType("image/gif");
anImage.setSizeInBytes(1023);
anImage.setWidth(100);
anImage.setIdentifier("AAAACCCDSA");
entityManager = factory.createEntityManager();
entityManager.getTransaction().begin();
}
@Test
public void find_and_save() {
entityManager.persist(anImage);
entityManager.getTransaction().commit();
UUID pk = anImage.getId();
entityManager.getTransaction().begin();
anImage = entityManager.find(Image.class, pk);
assertNotNull("Record was saved", anImage.getId());
assertEquals("Parent data saved", "/tmp/img1.gif" ,anImage.getUri());
assertTrue("Child data saved", anImage.getWidth() == 100);
}
@After
public void tearDown() {
entityManager.getTransaction().rollback();
entityManager.close();
}
}