public static void generateJavaFilesForOneStory(String storyFilePath,
            String platformName, String src_test_dir, String tests_package,
            String casemanager_package, String loggingPropFile)
            throws Exception {

        /*
         * This map has the following structure: {Scenario1ID =>
         * [GivenDescription1, WhenDescription1, ThenDescription1], Scenario2ID
         * => [GivenDescription2, WhenDescription2, ThenDescription2], ...}
         */
        HashMap<String, String[]> scenarios = new HashMap<String, String[]>();
        String storyName = null;
        String story_user = null;
        String user_feature = null;
        String user_benefit = null;
        BufferedReader fileReader = createFileReader(storyFilePath);
        if (fileReader == null) {
            logger.severe("ERROR Reading the file " + storyFilePath);
        } else {
            // Starting with the CaseManager
            // Shall I perish, may $Deity have mercy on my soul, and on those
            // who should finish this
            File caseManager = CreateSystemCaseManager.startSystemCaseManager(
                    casemanager_package, src_test_dir);
            try {
                String nextLine = null;
                // TYPES:
                // As a -> 1
                // I want to -> 2
                // So that -> 3
                int lineType = 0;
                while ((nextLine = fileReader.readLine()) != null) {

                    // Again, why am I using class variables to store the data
                    // I only fucking use in this method?

                    if (nextLine.startsWith("Story")) {
                        String aux = nextLine.replaceFirst("Story", "").trim();
                        if (aux.startsWith(":") || aux.startsWith("-")) {
                            aux = aux.substring(1).trim();
                        }
                        storyName = aux;
                    } else if (nextLine.startsWith("As a")) {
                        story_user = nextLine.replaceFirst("As a", "").trim();
                        lineType = 1;
                    } else if (nextLine.startsWith("I want to")) {
                        user_feature = nextLine.replaceFirst("I want to", "")
                                .trim();
                        lineType = 2;
                    } else if (nextLine.startsWith("So that")) {
                        user_benefit = nextLine.replaceFirst("So that", "")
                                .trim();
                        lineType = 3;
                    } else if (nextLine.startsWith("And")) {
                        switch (lineType) {
                        case 1:
                            story_user= story_user + " and " + nextLine.replaceFirst("And", "").trim();
                            break;
                        case 2:
                            user_feature= user_feature + " and " + nextLine.replaceFirst("And", "").trim();                            
                            break;
                        case 3:
                            user_benefit= user_benefit + " and " + nextLine.replaceFirst("And", "").trim();                            
                            break;
                        default:
                            break;
                        }
                    } else if (nextLine.startsWith("Scenario")) {

                        // I am assuming that the file is properly formated
                        // TODO: Check that it actually is properly formated.

                        String aux = nextLine.replaceFirst("Scenario", "").trim();
                        if (aux.startsWith(":") || aux.startsWith("-")) {
                            aux = aux.substring(1).trim();
                        }
                        aux.toLowerCase();
                        String scenarioID = createClassName(aux);
                        while (!fileReader.ready()) {
                            Thread.yield();
                        }
                        nextLine = fileReader.readLine();
                        String givenDescription = nextLine.replaceFirst(
                                "Given", "").trim();

                        while (!fileReader.ready()) {
                            Thread.yield();
                        }
                        nextLine = fileReader.readLine();
                        while (nextLine.startsWith("And")) {
                            givenDescription = givenDescription + " and " + nextLine.replaceFirst("And", "").trim();
                            while (!fileReader.ready()) {
                                Thread.yield();
                            }
                            nextLine = fileReader.readLine();
                        }
                        String whenDescription = nextLine.replaceFirst("When",
                                "").trim();

                        while (!fileReader.ready()) {
                            Thread.yield();
                        }
                        nextLine = fileReader.readLine();
                        while (nextLine.startsWith("And")) {
                            whenDescription = whenDescription + " and " + nextLine.replaceFirst("And", "").trim();
                            while (!fileReader.ready()) {
                                Thread.yield();
                            }
                            nextLine = fileReader.readLine();
                        }
                        String thenDescription = nextLine.replaceFirst("Then",
                                "").trim();
                        
                        nextLine = fileReader.readLine();
                        
                        while (nextLine!=null && nextLine.startsWith("And")) {
                            thenDescription = thenDescription +  " and " + nextLine.replaceFirst("And", "").trim();
                            nextLine = fileReader.readLine();
                        }

                        String[] scenarioData = new String[3];
                        scenarioData[0] = givenDescription;
                        scenarioData[1] = whenDescription;
                        scenarioData[2] = thenDescription;

                        scenarios.put(scenarioID, scenarioData);
                    } else if (!nextLine.trim().isEmpty()) {
                        // Is not an empty line, but has not been recognized.
                        logger.severe("ERROR: The test writen in the plain text can not be handed");
                        logger.severe("Try again whit the following key-words: {Story -,"
                                + " As a, I want to, So that, Scenario:, Given, When, Then}");
                    } // The only possibility here is to get an empty line,
                      // so I don't have to do anything.
                }

                fileReader.close();

                // Now, I should have all the variables set.

                if (storyName != null) {
                    // // I have a story, so...
                    if (fileDoesNotExist(createClassName(storyName) + ".java", tests_package,
                            src_test_dir)) {
                        CreateSystemTestSuite.createSystemTestSuite(storyName,
                                platformName, tests_package, src_test_dir,
                                loggingPropFile, story_user, user_feature,
                                user_benefit, scenarios);
                    }
                    CreateSystemCaseManager.addStory(caseManager, storyName,
                            tests_package, story_user, user_feature,
                            user_benefit);

                } else {

                    // This should not happen, since this class should only be
                    // used
                    // to create System tests, (i.e. "story" should never be
                    // null)

                    logger.severe("ERROR: No Story found in :" + storyFilePath);

                }

                CreateSystemCaseManager.closeSystemCaseManager(caseManager);

            } catch (Exception e) {
                logger.severe("ERROR: " + e.getMessage());
                throw e;
            }
        }
    }
public static void generateJavaFilesForOneStory ( String storyFilePath , String platformName , String src_test_dir , String tests_package , String casemanager_package , String loggingPropFile ) throws Exception { HashMap < String , String [ ] > scenarios = new HashMap < String , String [ ] > ( ) ; String storyName = null ; String story_user = null ; String user_feature = null ; String user_benefit = null ; BufferedReader fileReader = createFileReader ( storyFilePath ) ; if ( fileReader == null ) { logger . severe ( "ERROR Reading the file " + storyFilePath ) ; } else { File caseManager = CreateSystemCaseManager . startSystemCaseManager ( casemanager_package , src_test_dir ) ; try { String nextLine = null ; int lineType = 0 ; while ( ( nextLine = fileReader . readLine ( ) ) != null ) { if ( nextLine . startsWith ( "Story" ) ) { String aux = nextLine . replaceFirst ( "Story" , "" ) . trim ( ) ; if ( aux . startsWith ( ":" ) || aux . startsWith ( "-" ) ) { aux = aux . substring ( 1 ) . trim ( ) ; } storyName = aux ; } else if ( nextLine . startsWith ( "As a" ) ) { story_user = nextLine . replaceFirst ( "As a" , "" ) . trim ( ) ; lineType = 1 ; } else if ( nextLine . startsWith ( "I want to" ) ) { user_feature = nextLine . replaceFirst ( "I want to" , "" ) . trim ( ) ; lineType = 2 ; } else if ( nextLine . startsWith ( "So that" ) ) { user_benefit = nextLine . replaceFirst ( "So that" , "" ) . trim ( ) ; lineType = 3 ; } else if ( nextLine . startsWith ( "And" ) ) { switch ( lineType ) { case 1 : story_user = story_user + " and " + nextLine . replaceFirst ( "And" , "" ) . trim ( ) ; break ; case 2 : user_feature = user_feature + " and " + nextLine . replaceFirst ( "And" , "" ) . trim ( ) ; break ; case 3 : user_benefit = user_benefit + " and " + nextLine . replaceFirst ( "And" , "" ) . trim ( ) ; break ; default : break ; } } else if ( nextLine . startsWith ( "Scenario" ) ) { String aux = nextLine . replaceFirst ( "Scenario" , "" ) . trim ( ) ; if ( aux . startsWith ( ":" ) || aux . startsWith ( "-" ) ) { aux = aux . substring ( 1 ) . trim ( ) ; } aux . toLowerCase ( ) ; String scenarioID = createClassName ( aux ) ; while ( ! fileReader . ready ( ) ) { Thread . yield ( ) ; } nextLine = fileReader . readLine ( ) ; String givenDescription = nextLine . replaceFirst ( "Given" , "" ) . trim ( ) ; while ( ! fileReader . ready ( ) ) { Thread . yield ( ) ; } nextLine = fileReader . readLine ( ) ; while ( nextLine . startsWith ( "And" ) ) { givenDescription = givenDescription + " and " + nextLine . replaceFirst ( "And" , "" ) . trim ( ) ; while ( ! fileReader . ready ( ) ) { Thread . yield ( ) ; } nextLine = fileReader . readLine ( ) ; } String whenDescription = nextLine . replaceFirst ( "When" , "" ) . trim ( ) ; while ( ! fileReader . ready ( ) ) { Thread . yield ( ) ; } nextLine = fileReader . readLine ( ) ; while ( nextLine . startsWith ( "And" ) ) { whenDescription = whenDescription + " and " + nextLine . replaceFirst ( "And" , "" ) . trim ( ) ; while ( ! fileReader . ready ( ) ) { Thread . yield ( ) ; } nextLine = fileReader . readLine ( ) ; } String thenDescription = nextLine . replaceFirst ( "Then" , "" ) . trim ( ) ; nextLine = fileReader . readLine ( ) ; while ( nextLine != null && nextLine . startsWith ( "And" ) ) { thenDescription = thenDescription + " and " + nextLine . replaceFirst ( "And" , "" ) . trim ( ) ; nextLine = fileReader . readLine ( ) ; } String [ ] scenarioData = new String [ 3 ] ; scenarioData [ 0 ] = givenDescription ; scenarioData [ 1 ] = whenDescription ; scenarioData [ 2 ] = thenDescription ; scenarios . put ( scenarioID , scenarioData ) ; } else if ( ! nextLine . trim ( ) . isEmpty ( ) ) { logger . severe ( "ERROR: The test writen in the plain text can not be handed" ) ; logger . severe ( "Try again whit the following key-words: {Story -," + " As a, I want to, So that, Scenario:, Given, When, Then}" ) ; } } fileReader . close ( ) ; if ( storyName != null ) { if ( fileDoesNotExist ( createClassName ( storyName ) + ".java" , tests_package , src_test_dir ) ) { CreateSystemTestSuite . createSystemTestSuite ( storyName , platformName , tests_package , src_test_dir , loggingPropFile , story_user , user_feature , user_benefit , scenarios ) ; } CreateSystemCaseManager . addStory ( caseManager , storyName , tests_package , story_user , user_feature , user_benefit ) ; } else { logger . severe ( "ERROR: No Story found in :" + storyFilePath ) ; } CreateSystemCaseManager . closeSystemCaseManager ( caseManager ) ; } catch ( Exception e ) { logger . severe ( "ERROR: " + e . getMessage ( ) ) ; throw e ; } } }
Main method of the class, which handles all the process to create all
tests.

@param storyFilePath
, it is the folder where the plain text given by the client is
stored
@param platformName
, to choose the MAS platform (JADE, JADEX, etc.)
@param src_test_dir
, the folder where our classes are created
@param tests_package
, the name of the package where the stories are created
@param casemanager_package
, the path where casemanager must be created
@param loggingPropFile
, properties file
@throws Exception
, if any error is found in the configuration