/*
 * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
 *
 * 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.jboss.hal.testsuite.test.configuration.jpa;

import org.jboss.arquillian.core.api.annotation.Inject;
import org.jboss.arquillian.graphene.page.Page;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.hal.testsuite.Console;
import org.jboss.hal.testsuite.creaper.ManagementClientProvider;
import org.jboss.hal.testsuite.creaper.ResourceVerifier;
import org.jboss.hal.testsuite.creaper.command.BackupAndRestoreAttributes;
import org.jboss.hal.testsuite.fragment.FormFragment;
import org.jboss.hal.testsuite.page.configuration.JpaPage;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.extras.creaper.core.CommandFailedException;
import org.wildfly.extras.creaper.core.online.OnlineManagementClient;

import static org.jboss.hal.testsuite.test.configuration.jpa.JpaFixtures.DEFAULT_EXTENDED_PERSISTENCE_INHERITANCE;
import static org.jboss.hal.testsuite.test.configuration.jpa.JpaFixtures.SHALLOW;
import static org.jboss.hal.testsuite.test.configuration.jpa.JpaFixtures.SUBSYSTEM_ADDRESS;

@RunWith(Arquillian.class)
public class JpaTest {

    private static final OnlineManagementClient client = ManagementClientProvider.createOnlineManagementClient();
    private static BackupAndRestoreAttributes backup;

    @BeforeClass
    public static void beforeClass() throws CommandFailedException {
        backup = new BackupAndRestoreAttributes.Builder(SUBSYSTEM_ADDRESS).build();
        client.apply(backup.backup());
    }

    @AfterClass
    public static void afterClass() throws CommandFailedException {
        client.apply(backup.restore());
    }

    @Inject private Console console;
    @Page private JpaPage page;
    private FormFragment form;

    @Before
    public void setUp() throws Exception {
        page.navigate();
        form = page.getForm();
    }

    @Test
    public void update() throws Exception {
        form.edit();
        form.select(DEFAULT_EXTENDED_PERSISTENCE_INHERITANCE, SHALLOW);
        form.save();

        console.verifySuccess();
        new ResourceVerifier(SUBSYSTEM_ADDRESS, client)
                .verifyAttribute(DEFAULT_EXTENDED_PERSISTENCE_INHERITANCE, SHALLOW);
    }

    @Test
    public void reset() throws Exception {
        form.reset();
        console.verifySuccess();
        new ResourceVerifier(SUBSYSTEM_ADDRESS, client)
                .verifyReset();
    }
}

@@ -859,22 +859,29 @@
 tsuite.C
+rudOperati
 ons
-ole
 ;%0Aimport
@@ -943,65 +943,8 @@
 er;%0A
-import org.jboss.hal.testsuite.creaper.ResourceVerifier;%0A
 impo
@@ -2283,22 +2283,26 @@
 te C
-onsole console
+rudOperations crud
 ;%0A  
@@ -2547,29 +2547,60 @@
     
-form.edit();%0A
+crud.update(SUBSYSTEM_ADDRESS, form,%0A       
         
 form
@@ -2595,20 +2595,23 @@
         
-form
+ f -%3E f
 .select(
@@ -2656,25 +2656,25 @@
 CE, SHALLOW)
-;
+,
 %0A        for
@@ -2674,127 +2674,52 @@
     
-form.save();%0A%0A        console.verifySuccess();%0A        new ResourceVerifier(SUBSYSTEM_ADDRESS, client)%0A                
+        resourceVerifier -%3E resourceVerifier
 .ver
@@ -2764,32 +2764,56 @@
 NCE_INHERITANCE,
+%0A                       
  SHALLOW);%0A    %7D
@@ -2805,16 +2805,17 @@
 SHALLOW)
+)
 ;%0A    %7D%0A
@@ -2880,140 +2880,42 @@
     
-form
+crud
 .reset(
-);%0A        console.verifySuccess();%0A        new ResourceVerifier(SUBSYSTEM_ADDRESS, client)%0A                .verifyReset(
+SUBSYSTEM_ADDRESS, form
 );%0A 

Use CrudOperations in JPA tests