/* 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.camunda.bpm.model.bpmn.instance;

import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.bpmn.impl.instance.Incoming;
import org.camunda.bpm.model.bpmn.impl.instance.Outgoing;
import org.camunda.bpm.model.xml.instance.ModelElementInstance;
import org.junit.Test;

import java.io.File;
import java.util.Arrays;
import java.util.Collection;

/**
 * @author Sebastian Menski
 */
public class FlowNodeTest extends BpmnModelElementInstanceTest {

  public TypeAssumption getTypeAssumption() {
    return new TypeAssumption(FlowElement.class, true);
  }

  public Collection<ChildElementAssumption> getChildElementAssumptions() {
    return Arrays.asList(
      new ChildElementAssumption(Incoming.class),
      new ChildElementAssumption(Outgoing.class)
    );
  }

  public Collection<AttributeAssumption> getAttributesAssumptions() {
    return null;
  }

  @Test
  public void test() {
    BpmnModelInstance modelInstance = Bpmn.createProcess().startEvent().userTask("test").endEvent().done();
    Bpmn.writeModelToFile(new File("/tmp/before.bpmn"), modelInstance);
    ServiceTask serviceTask = modelInstance.newInstance(ServiceTask.class);
    serviceTask.setId("new");
    ModelElementInstance test = modelInstance.getModelElementById("test");
    test.replaceWithElement(serviceTask);
    Bpmn.writeModelToFile(new File("/tmp/after.bpmn"), modelInstance);
  }
}

@@ -823,113 +823,28 @@
 org.
-camunda.bpm.model.xml.instance.ModelElementInstance
+junit.Test
 ;%0A
+%0A
 import 
-org.junit.Test;%0A%0Aimport java.io.File;%0Aimport 
 java
@@ -884,16 +884,75 @@
 llection
+;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat
 ;%0A%0A/**%0A 
@@ -1485,16 +1485,51 @@
 oid test
+UpdateIncomingOutgoingChildElements
 () %7B%0A   
@@ -1583,16 +1583,23 @@
 rocess()
+%0A      
 .startEv
@@ -1603,16 +1603,23 @@
 tEvent()
+%0A      
 .userTas
@@ -1627,16 +1627,23 @@
 (%22test%22)
+%0A      
 .endEven
@@ -1645,16 +1645,23 @@
 dEvent()
+%0A      
 .done();
@@ -1665,79 +1665,294 @@
 ();%0A
+%0A
     
-Bpmn.writeModelToFile(new File(%22/tmp/before.bpmn%22), modelInstance);
+// save current incoming and outgoing sequence flows%0A    UserTask userTask = modelInstance.getModelElementById(%22test%22);%0A    Collection%3CSequenceFlow%3E incoming = userTask.getIncoming();%0A    Collection%3CSequenceFlow%3E outgoing = userTask.getOutgoing();%0A%0A    // create a new service task
 %0A   
@@ -2058,91 +2058,76 @@
 %22);%0A
+%0A
     
-ModelElementInstance test = modelInstance.getModelElementById(%22test%22);%0A    test
+// replace the user task with the new service task%0A    userTask
 .rep
@@ -2160,76 +2160,254 @@
 k);%0A
+%0A
     
-Bpmn.writeModelToFile(new File(%22/tmp/after.bpmn%22), modelInstance
+// assert that the new service task has the same incoming and outgoing sequence flows%0A    assertThat(serviceTask.getIncoming()).containsExactlyElementsOf(incoming);%0A    assertThat(serviceTask.getOutgoing()).containsExactlyElementsOf(outgoing
 );%0A 

fix flow node update child element test