/** * Store scene in file * */ public void writeScene(Scene scene) throws IOException { File file = new File(scene.getSceneRoot(), scene.getName()); File parent = file.getParentFile(); if (!parent.exists() && !parent.mkdirs()) { throw new IllegalStateException("Failed to create new directory: " + parent); } BufferedWriter bufferedWriter = Files.newWriter(file, Charset.forName(SceneSerializationConstant.FILE_CHARSET)); SceneSerializer sceneSerializer = new SceneSerializer(); sceneSerializer.serialize(scene, bufferedWriter); } }
@Test public void testCreateSceneNotExistInRecordMode() throws Exception { Scene result = runTestGetResult(SceneMode.RECORD, null); Assert.assertNotNull(result); Assert.assertEquals(result.getName(), NAME); Assert.assertEquals(result.getSceneRoot(), ROOT); Assert.assertFalse(result.isReadable()); }
@Test public void testCreateSceneExistInPlaybackMode() throws Exception { Scene expectedScene = EasyMock.createStrictMock(Scene.class); List<RecordedHttpExchange> recordedHttpExchanges = new ArrayList<>(); Date now = new Date(); recordedHttpExchanges.add(new RecordedHttpExchange(null, null, now)); EasyMock.expect(expectedScene.getRecordedHttpExchangeList()).andReturn(recordedHttpExchanges); EasyMock.replay(expectedScene); Scene result = runTestGetResult(SceneMode.PLAYBACK, expectedScene); Assert.assertNotNull(result); Assert.assertEquals(result.getName(), NAME); Assert.assertEquals(result.getSceneRoot(), ROOT); Assert.assertTrue(result.isReadable()); Assert.assertEquals(result.getRecordedHttpExchangeList().get(0).getUpdateTime(), now); }
@Test public void testCreateSceneExistInSequentialRecordMode() throws Exception { Scene expectedScene = EasyMock.createStrictMock(Scene.class); List<RecordedHttpExchange> recordedHttpExchanges = new ArrayList<>(); Date now = new Date(); recordedHttpExchanges.add(new RecordedHttpExchange(null, null, now)); EasyMock.expect(expectedScene.getRecordedHttpExchangeList()).andReturn(recordedHttpExchanges); EasyMock.replay(expectedScene); Scene result = runTestGetResult(SceneMode.SEQUENTIAL_RECORD, expectedScene); Assert.assertNotNull(result); Assert.assertEquals(result.getName(), NAME); Assert.assertEquals(result.getSceneRoot(), ROOT); Assert.assertFalse(result.isReadable()); // Creating a Scene in sequential record mode should clear the list of exchanges to allow for re-recording Assert.assertEquals(result.getRecordedHttpExchangeList().size(), 0); }
@Test public void testCreateSceneExistInRecordMode() throws Exception { Scene expectedScene = EasyMock.createStrictMock(Scene.class); List<RecordedHttpExchange> recordedHttpExchanges = new ArrayList<>(); Date now = new Date(); recordedHttpExchanges.add(new RecordedHttpExchange(null, null, now)); EasyMock.expect(expectedScene.getRecordedHttpExchangeList()).andReturn(recordedHttpExchanges); EasyMock.replay(expectedScene); Scene result = runTestGetResult(SceneMode.RECORD, expectedScene); Assert.assertNotNull(result); Assert.assertEquals(result.getName(), NAME); Assert.assertEquals(result.getSceneRoot(), ROOT); Assert.assertFalse(result.isReadable()); Assert.assertEquals(result.getRecordedHttpExchangeList().get(0).getUpdateTime(), now); }