@@ -0,0 +1,2952 @@
+package eu.itesla_project.iidm.network.impl;%0A%0Aimport com.google.common.collect.Sets;%0Aimport eu.itesla_project.commons.ITeslaException;%0Aimport eu.itesla_project.iidm.network.Network;%0Aimport eu.itesla_project.iidm.network.StateManager;%0Aimport eu.itesla_project.iidm.network.test.NoEquipmentNetworkFactory;%0Aimport org.junit.Before;%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.ExpectedException;%0A%0Aimport java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.fail;%0A%0Apublic class ManipulationsOnStatesTest %7B%0A%0A    @Rule%0A    public ExpectedException thrown = ExpectedException.none();%0A%0A    private StateManager stateManager;%0A%0A    @Before%0A    public void setUp() %7B%0A        Network network = NoEquipmentNetworkFactory.create();%0A        stateManager = network.getStateManager();%0A    %7D%0A%0A    @Test%0A    public void errorRemoveInitialState() %7B%0A        thrown.expect(ITeslaException.class);%0A        thrown.expectMessage(%22Removing initial state is forbidden%22);%0A        stateManager.removeState(StateManager.INITIAL_STATE_ID);%0A    %7D%0A%0A    @Test%0A    public void errorNotExistingState() %7B%0A        thrown.expect(ITeslaException.class);%0A        thrown.expectMessage(%22not found%22);%0A        stateManager.removeState(%22not_exists%22);%0A    %7D%0A%0A    @Test%0A    public void errorCloneToEmptyStates() %7B%0A        thrown.expect(IllegalArgumentException.class);%0A        thrown.expectMessage(%22Empty target state id list%22);%0A        stateManager.cloneState(StateManager.INITIAL_STATE_ID, Collections.emptyList());%0A    %7D%0A%0A    @Test%0A    public void errorCloneToExistingState() %7B%0A        stateManager.cloneState(StateManager.INITIAL_STATE_ID, %22hello%22);%0A        thrown.expect(ITeslaException.class);%0A        thrown.expectMessage(%22already exists%22);%0A        stateManager.cloneState(StateManager.INITIAL_STATE_ID, %22hello%22);%0A    %7D%0A%0A    @Test%0A    public void baseTests() %7B%0A        List%3CString%3E statesToAdd = Arrays.asList(%22s1%22, %22s2%22, %22s3%22, %22s4%22);%0A        // extend%0A        stateManager.cloneState(StateManager.INITIAL_STATE_ID, statesToAdd);%0A        assertEquals(Sets.newHashSet(StateManager.INITIAL_STATE_ID, %22s1%22, %22s2%22, %22s3%22, %22s4%22), stateManager.getStateIds());%0A%0A        // delete%0A        stateManager.removeState(%22s2%22);%0A        assertEquals(Sets.newHashSet(StateManager.INITIAL_STATE_ID, %22s1%22, %22s3%22, %22s4%22), stateManager.getStateIds());%0A%0A        // allocate%0A        stateManager.cloneState(%22s4%22, %22s2b%22);%0A        assertEquals(Sets.newHashSet(StateManager.INITIAL_STATE_ID, %22s1%22, %22s2b%22, %22s3%22, %22s4%22), stateManager.getStateIds());%0A%0A        // reduce%0A        stateManager.setWorkingState(%22s4%22);%0A        stateManager.removeState(%22s4%22);%0A        assertEquals(Sets.newHashSet(StateManager.INITIAL_STATE_ID, %22s2b%22, %22s1%22, %22s3%22), stateManager.getStateIds());%0A%0A        try %7B%0A            stateManager.getWorkingStateId();%0A            fail();%0A        %7D catch (Exception ignored) %7B%0A        %7D%0A    %7D%0A%7D%0A

Add clone/remove/invalid_manipulation state tests on StateManager