jerseyテストフレームワークを使用してジャーナルエンドポイントをテストしようとしています。テストクラスに@ org.springframework.transaction.annotation.Transactionalというアノテーションを付けました。テストは正常に実行されていますが、ロールバックは実行されません。コンソール@トランザクションがjunitテストの後にロールバックしない
INFO ] 2016-06-27 18:00:14.880 [main] AuthenticationFilter - 226
[INFO ] 2016-06-27 18:00:14.881 [main] AuthenticationFilter - 202f660a-00e9-436e-af48-bcc7dcbd85c9
[INFO ] 2016-06-27 18:00:14.974 [main] OffersController - insert inside the InsertOfferController
[INFO ] 2016-06-27 18:00:14.975 [main] OffersServicesImpl - Insert offerInsert Services
[INFO ] 2016-06-27 18:00:15.009 [main] TransactionContext - **Rolled back transaction for test context** [[email protected] testClass = OfferControllerTest, testInstance = [email protected], testMethod = [email protected], testException = [null], mergedContextConfiguration = [[email protected] testClass = OfferControllerTest, locations = '{}', classes = '{class com.my.MyApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'org.springframework.boot.test.SpringApplicationContextLoader', parent = [null]]].
で
OfferControllerTest
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(MyApplication.class)
@Transactional
public class OfferControllerTest extends JerseyTest {
@Test
public void insertOrderTest() {
Entity<InsertOffersRequest> insertOffersRequestEntity = Entity.entity(insertOffersRequest,
MediaType.APPLICATION_JSON_TYPE);
Response response = target(SavioUriConstants.ORDER_INSERT).register(provider)
.register(HttpAuthenticationFeature.basic(env.getProperty("username"), env.getProperty("password")))
.request(MediaType.APPLICATION_JSON_TYPE).post(insertOffersRequestEntity);
assertEquals(200, response.getStatus());
assertEquals("OFFERS IS ADDED SUCCESSFULLY", response.readEntity(OfferInsertResponse.class).getMessage());
}
OfferServiceImpl
@Service
public class OffersServicesImpl implements OffersService{
public OfferInsertResponse insertOffers(InsertOffersRequest request) {
log.info("Insert offerInsert Services");
Offers offers = new Offers();
offers.setOffImage(request.getImage());
offers.setOffLogo(request.getLogo());
offers.setOffCompanyName(request.getCompanyName());
Offers offer = (Offers) offersRepository.save(offers);
iが行がテストクラスによって挿入ロールバックする方法を任意のアイデア?
REST(つまりHTTP)コールがトランザクションになることをどのように期待しますか?それは明らかに起こることはありません。 –
この場合、どうすればいいですか? –
実際のデータベースを汚染しないように、リポジトリをモックアウトするか、またはメモリ内のデータベースを設定してください。テスト目的でSpring-Bootを使用してメモリ内のデータベースを設定するのは簡単です。 –