/*
 * Copyright (c) 2004-2019, University of Oslo
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * Neither the name of the HISP project nor the names of its contributors may
 * be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.hisp.dhis.android.testapp.dataset;

import org.hisp.dhis.android.core.common.State;
import org.hisp.dhis.android.core.dataset.DataSetCompleteRegistration;
import org.hisp.dhis.android.core.dataset.DataSetCompleteRegistrationObjectRepository;
import org.hisp.dhis.android.core.maintenance.D2Error;
import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestFullDispatcher;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

public class DataSetCompleteRegistrationObjectRepositoryMockIntegrationShould extends BaseMockIntegrationTestFullDispatcher {

    @Test
    public void delete() {

        List<DataSetCompleteRegistration> dataSetCompleteRegistrations = d2.dataSetModule().dataSetCompleteRegistrations().blockingGet();

        try {
            objectRepository().blockingDelete();
        } catch (D2Error d2Error) {
            Assert.fail();
        }

        DataSetCompleteRegistration dataSetCompleteRegistration = objectRepository().blockingGet();

        assertThat(dataSetCompleteRegistration.deleted(), is(true));
        assertThat(dataSetCompleteRegistration.state(), is(State.TO_UPDATE));

    }

    private DataSetCompleteRegistrationObjectRepository objectRepository() {
        return d2.dataSetModule().dataSetCompleteRegistrations().value(
                "2018", "DiszpKrYNg8", "lyLU2wR22tC","bRowv6yZOF2");
    }
}

@@ -2009,32 +2009,8 @@
 t;%0A%0A
-import java.util.List;%0A%0A
 impo
@@ -2096,16 +2096,105 @@
 e.Is.is;
+%0Aimport static org.junit.Assert.assertNotNull;%0Aimport static org.junit.Assert.assertNull;
 %0A%0Apublic
@@ -2322,180 +2322,178 @@
     
-@Test%0A    public void delete() %7B%0A%0A        List%3CDataSetCompleteRegistration%3E dataSetCompleteRegistrations = d2.dataSetModule().dataSetCompleteRegistrations().blockingG
+private String dataSetUid = %22lyLU2wR22tC%22;%0A    private String orgUnitUid = %22DiszpKrYNg8%22;%0A    private String cocUid = %22bRowv6yZOF2%22;%0A%0A    @Test%0A    public void del
 et
+e
 ()
-;%0A
+ %7B
 %0A   
@@ -2874,17 +2874,16 @@
 DATE));%0A
-%0A
     %7D%0A%0A 
@@ -2885,23 +2885,92 @@
  %7D%0A%0A    
-private
+@Test%0A    public void delete_newly_created_record() throws D2Error %7B%0A       
  DataSet
@@ -3006,17 +3006,20 @@
 ository 
-o
+newO
 bjectRep
@@ -3025,20 +3025,18 @@
 pository
-() %7B
+ =
 %0A       
@@ -3040,14 +3040,15 @@
     
-return
+       
  d2.
@@ -3104,75 +3104,574 @@
 lue(
-%0A                %222018%22, %22DiszpKrYNg8%22, %22lyLU2wR22tC%22,%22bRowv6yZOF2%22
+%222019%22, orgUnitUid, dataSetUid, cocUid);%0A%0A        newObjectRepository.blockingSet();%0A        newObjectRepository.blockingDelete();%0A%0A        DataSetCompleteRegistration newObject = newObjectRepository.blockingGet();%0A        assertNull(newObject);%0A%0A        DataSetCompleteRegistration existingObject = objectRepository().blockingGet();%0A        assertNotNull(existingObject);%0A    %7D%0A%0A    private DataSetCompleteRegistrationObjectRepository objectRepository() %7B%0A        return d2.dataSetModule().dataSetCompleteRegistrations().value(%222018%22, orgUnitUid, dataSetUid, cocUid
 );%0A 

Add integration test