// Path: src/main/java/com/hantsylabs/restexample/springmvc/repository/PostRepository.java
// public interface PostRepository extends JpaRepository<Post, Long>,//
//         JpaSpecificationExecutor<Post>{
// 
// }
// 
// Path: src/test/java/com/hantsylabs/restexample/springmvc/test/jbehave/AbstractSpringJBehaveStory.java
// @Slf4j
// public abstract class AbstractSpringJBehaveStory extends JUnitStory {
// 
//     @Inject
//     PostRepository posts;
// 
//     @Inject
//     CommentRepository comments;
// 
//     @Inject
//     UserRepository users;
// 
//     @Inject
//     PasswordEncoder passwordEncoder;
// 
//     public void clearData() {
//         log.debug("clearing data...");
// 
//         comments.deleteAllInBatch();
//         posts.deleteAllInBatch();
//         users.deleteAllInBatch();
//     }
// 
//     public void initData() {
// 
//         users.save(
//                 User.builder()
//                 .username("admin")
//                 .password(passwordEncoder.encode("test123"))
//                 .name("Administrator")
//                 .role("ADMIN")
//                 .build()
//         );
//     }
// 
//     private static final String STORY_TIMEOUT_IN_SECONDS = "120";
// 
//     public AbstractSpringJBehaveStory() {
//         Embedder embedder = new Embedder();
//         embedder.useEmbedderControls(embedderControls());
//         embedder.useMetaFilters(Arrays.asList("-skip"));
//         useEmbedder(embedder);
//     }
// 
//     @Override
//     public Configuration configuration() {
//         return new MostUsefulConfiguration()
//                 .useStoryPathResolver(storyPathResolver())
//                 .useStoryLoader(storyLoader())
//                 .useStoryReporterBuilder(storyReporterBuilder())
//                 .useParameterControls(parameterControls());
//     }
// 
//     @Override
//     public InjectableStepsFactory stepsFactory() {
//         return new InstanceStepsFactory(configuration(), getSteps());
//     }
// 
//     private EmbedderControls embedderControls() {
//         return new EmbedderControls()
//                 .doIgnoreFailureInView(false)
//                 .doIgnoreFailureInStories(false)
//                 .doVerboseFailures(true)
//                 .doVerboseFiltering(true)
//                 .useStoryTimeouts(STORY_TIMEOUT_IN_SECONDS);
//     }
// 
//     private ParameterControls parameterControls() {
//         return new ParameterControls()
//                 .useDelimiterNamedParameters(true);
//     }
// 
//     private StoryPathResolver storyPathResolver() {
//         return new UnderscoredCamelCaseResolver();
//     }
// 
//     private StoryLoader storyLoader() {
//         return new LoadFromClasspath();
//     }
// 
//     private StoryReporterBuilder storyReporterBuilder() {
//         return new StoryReporterBuilder()
//                 .withCodeLocation(CodeLocations.codeLocationFromClass(this.getClass()))
//                 .withPathResolver(new ResolveToPackagedName())
//                 .withFailureTrace(true)
//                 .withDefaultFormats()
//                 .withFormats(IDE_CONSOLE, TXT, HTML);
//     }
// 
//     public abstract Object[] getSteps();
// }
// 
// Path: src/test/java/com/hantsylabs/restexample/springmvc/test/jbehave/steps/PostSteps.java
// public class PostSteps {
// 
//     PostRepository postRepository;
// 
//     TestRestTemplate restTemplate;
// 
//     String baseUrl;
// 
//     public PostSteps(PostRepository postRepository,
//             TestRestTemplate restTemplate,
//             String baseUrl) {
//         this.postRepository = postRepository;
//         this.restTemplate = restTemplate;
//         this.baseUrl = baseUrl;
//     }
// 
//     ResponseEntity<String> reponseEntity;
// 
//     @Given("post title is $title and content is $content")
//     public void savePost(@Named("title") String title, @Named("content") String content) {
//         postRepository.save(new Post(title, content));
//     }
// 
//     @When("GET $path")
//     public void getPost(@Named("path") String path) {
//         reponseEntity = restTemplate.getForEntity(baseUrl + path, String.class);
//     }
// 
//     @Then("response status is $code")
//     public void responseCode(@Named("code") int code) {
//         assertTrue(reponseEntity.getStatusCode().value() == code);
//     }
// 
//     @Then("response body contains $body")
//     public void responseBody(@Named("body") String body) {
//         assertTrue(reponseEntity.getBody().contains(body));
//     }
// 
// }


import com.hantsylabs.restexample.springmvc.repository.PostRepository;
import com.hantsylabs.restexample.springmvc.test.jbehave.AcceptanceTest;
import com.hantsylabs.restexample.springmvc.test.jbehave.AbstractSpringJBehaveStory;
import com.hantsylabs.restexample.springmvc.test.jbehave.steps.PostSteps;
import javax.inject.Inject;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.client.TestRestTemplate.HttpClientOption;
import org.springframework.test.context.junit4.SpringRunner;
package com.hantsylabs.restexample.springmvc.test.jbehave.stories;



@RunWith(SpringRunner.class)
@AcceptanceTest
public class PostStory extends AbstractSpringJBehaveStory {

    @Inject
    PostRepository postRepository;

    TestRestTemplate restTemplate;

    String baseUrl;

    @LocalServerPort
    int port;

    @Before
    public void setup() {
        clearData();
        initData();
        this.baseUrl = "http://localhost:" + port;
        this.restTemplate = new TestRestTemplate("admin", "test123", new HttpClientOption[]{});
    }

    @Override
    public Object[] getSteps() {
// Path: src/main/java/com/hantsylabs/restexample/springmvc/repository/PostRepository.java
// public interface PostRepository extends JpaRepository<Post, Long>,//
//         JpaSpecificationExecutor<Post>{
// 
// }
// 
// Path: src/test/java/com/hantsylabs/restexample/springmvc/test/jbehave/AbstractSpringJBehaveStory.java
// @Slf4j
// public abstract class AbstractSpringJBehaveStory extends JUnitStory {
// 
//     @Inject
//     PostRepository posts;
// 
//     @Inject
//     CommentRepository comments;
// 
//     @Inject
//     UserRepository users;
// 
//     @Inject
//     PasswordEncoder passwordEncoder;
// 
//     public void clearData() {
//         log.debug("clearing data...");
// 
//         comments.deleteAllInBatch();
//         posts.deleteAllInBatch();
//         users.deleteAllInBatch();
//     }
// 
//     public void initData() {
// 
//         users.save(
//                 User.builder()
//                 .username("admin")
//                 .password(passwordEncoder.encode("test123"))
//                 .name("Administrator")
//                 .role("ADMIN")
//                 .build()
//         );
//     }
// 
//     private static final String STORY_TIMEOUT_IN_SECONDS = "120";
// 
//     public AbstractSpringJBehaveStory() {
//         Embedder embedder = new Embedder();
//         embedder.useEmbedderControls(embedderControls());
//         embedder.useMetaFilters(Arrays.asList("-skip"));
//         useEmbedder(embedder);
//     }
// 
//     @Override
//     public Configuration configuration() {
//         return new MostUsefulConfiguration()
//                 .useStoryPathResolver(storyPathResolver())
//                 .useStoryLoader(storyLoader())
//                 .useStoryReporterBuilder(storyReporterBuilder())
//                 .useParameterControls(parameterControls());
//     }
// 
//     @Override
//     public InjectableStepsFactory stepsFactory() {
//         return new InstanceStepsFactory(configuration(), getSteps());
//     }
// 
//     private EmbedderControls embedderControls() {
//         return new EmbedderControls()
//                 .doIgnoreFailureInView(false)
//                 .doIgnoreFailureInStories(false)
//                 .doVerboseFailures(true)
//                 .doVerboseFiltering(true)
//                 .useStoryTimeouts(STORY_TIMEOUT_IN_SECONDS);
//     }
// 
//     private ParameterControls parameterControls() {
//         return new ParameterControls()
//                 .useDelimiterNamedParameters(true);
//     }
// 
//     private StoryPathResolver storyPathResolver() {
//         return new UnderscoredCamelCaseResolver();
//     }
// 
//     private StoryLoader storyLoader() {
//         return new LoadFromClasspath();
//     }
// 
//     private StoryReporterBuilder storyReporterBuilder() {
//         return new StoryReporterBuilder()
//                 .withCodeLocation(CodeLocations.codeLocationFromClass(this.getClass()))
//                 .withPathResolver(new ResolveToPackagedName())
//                 .withFailureTrace(true)
//                 .withDefaultFormats()
//                 .withFormats(IDE_CONSOLE, TXT, HTML);
//     }
// 
//     public abstract Object[] getSteps();
// }
// 
// Path: src/test/java/com/hantsylabs/restexample/springmvc/test/jbehave/steps/PostSteps.java
// public class PostSteps {
// 
//     PostRepository postRepository;
// 
//     TestRestTemplate restTemplate;
// 
//     String baseUrl;
// 
//     public PostSteps(PostRepository postRepository,
//             TestRestTemplate restTemplate,
//             String baseUrl) {
//         this.postRepository = postRepository;
//         this.restTemplate = restTemplate;
//         this.baseUrl = baseUrl;
//     }
// 
//     ResponseEntity<String> reponseEntity;
// 
//     @Given("post title is $title and content is $content")
//     public void savePost(@Named("title") String title, @Named("content") String content) {
//         postRepository.save(new Post(title, content));
//     }
// 
//     @When("GET $path")
//     public void getPost(@Named("path") String path) {
//         reponseEntity = restTemplate.getForEntity(baseUrl + path, String.class);
//     }
// 
//     @Then("response status is $code")
//     public void responseCode(@Named("code") int code) {
//         assertTrue(reponseEntity.getStatusCode().value() == code);
//     }
// 
//     @Then("response body contains $body")
//     public void responseBody(@Named("body") String body) {
//         assertTrue(reponseEntity.getBody().contains(body));
//     }
// 
// }


// Path: src/test/java/com/hantsylabs/restexample/springmvc/test/jbehave/stories/PostStory.java
import com.hantsylabs.restexample.springmvc.repository.PostRepository;
import com.hantsylabs.restexample.springmvc.test.jbehave.AcceptanceTest;
import com.hantsylabs.restexample.springmvc.test.jbehave.AbstractSpringJBehaveStory;
import com.hantsylabs.restexample.springmvc.test.jbehave.steps.PostSteps;
import javax.inject.Inject;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.client.TestRestTemplate.HttpClientOption;
import org.springframework.test.context.junit4.SpringRunner;

package com.hantsylabs.restexample.springmvc.test.jbehave.stories;



@RunWith(SpringRunner.class)
@AcceptanceTest
public class PostStory extends AbstractSpringJBehaveStory {

    @Inject
    PostRepository postRepository;

    TestRestTemplate restTemplate;

    String baseUrl;

    @LocalServerPort
    int port;

    @Before
    public void setup() {
        clearData();
        initData();
        this.baseUrl = "http://localhost:" + port;
        this.restTemplate = new TestRestTemplate("admin", "test123", new HttpClientOption[]{});
    }

    @Override
    public Object[] getSteps() {
        return new Object[]{new PostSteps(postRepository, restTemplate, baseUrl)};