/**
* Copyright 2011 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.bricket.plugin.picture.service;
import junit.framework.Assert;
import org.bricket.plugin.picture.domain.Picture;
import org.bricket.service.BricketServiceException;
import org.bricket.testsupport.AbstractBricketContextTest;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @author Ingo Renner
* @author Henning Teek
*
*/
public class PictureServiceTest extends AbstractBricketContextTest {
@Autowired
private PictureService pictureService;
@Before
public void setUp() throws BricketServiceException {
pictureService.init();
}
@Test
public void testPicture() {
Picture p = createPicture();
checkPicture(p);
updatePicture(p);
checkPicture(p);
deletePicture(p);
}
private void deletePicture(Picture p) {
pictureService.deletePicture(p);
Picture dm = pictureService.loadPicture(p.getId());
Assert.assertNull("expected null but got " + dm, dm);
}
private void updatePicture(Picture p) {
p.setTitle("title_2");
p.setDescription("description_2");
p.setDigest("digest_2");
pictureService.savePicture(p);
}
private void checkPicture(Picture p) {
Picture mp = pictureService.loadPicture(p.getId());
Assert.assertEquals(mp.getTitle(), p.getTitle());
Assert.assertEquals(mp.getDescription(), p.getDescription());
Assert.assertEquals(mp.getDigest(), p.getDigest());
// equal impl test
Assert.assertEquals(p, mp);
}
private Picture createPicture() {
Picture p = pictureService.createDomainObject();
p.setTitle("title_1");
p.setDescription("description_1");
p.setDigest("digest_1");
p = pictureService.savePicture(p);
Assert.assertTrue("expected id but got:" + p.getId(), p.getId() != null);
return p;
}
}