Skip to content

Commit

Permalink
Small fixes + Localized Templates... + add modified jbehave keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnauld committed Jun 3, 2012
1 parent b475e73 commit d784e1e
Show file tree
Hide file tree
Showing 20 changed files with 433 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Eclipse Application (1).launch

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions jbehave_templates/jbehave_templates_en.xml
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<template
context="org.technbolts.jbehave.story"
description="Story sample"
id="org.technbolts.jbehave.story.sample1_en"
autoinsert="true"
name="sample1">${Scenario} trader is not alerted below threshold

${Given} a stock of symbol ${symbol} and a threshold of ${threshold:10.0f}
${When} the stock is traded at ${value:5.0}
${Then} the alert status should be ${status:OFF}
</template>
<template
context="org.technbolts.jbehave.story"
description="Story sample with narrative and two scenario"
id="org.technbolts.jbehave.story.sample2_en"
autoinsert="true"
name="sample2">A story is a collection of scenarios

${Narrative}
${InOrderTo} communicate effectively to the business some functionality
${AsA} development team
${IWantTo} use Behaviour-Driven Development

${Scenario} A scenario is a collection of executable steps of different type

${Given} step represents a precondition to an event
${When} step represents the occurrence of the event
${Then} step represents the outcome of the event

${Scenario} Another scenario exploring different combination of events

${Given} a precondition
${When} a negative event occurs
${Then} a the outcome should be captured
</template>
</templates>
38 changes: 38 additions & 0 deletions jbehave_templates/jbehave_templates_fr.xml
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<template
context="org.technbolts.jbehave.story"
description="Story sample"
id="org.technbolts.jbehave.story.sample1_fr"
autoinsert="true"
name="sample1">${Scenario} trader is not alerted below threshold

${Given} a stock of symbol ${symbol} and a threshold of ${threshold:10.0f}
${When} the stock is traded at ${value:5.0}
${Then} the alert status should be ${status:OFF}
</template>
<template
context="org.technbolts.jbehave.story"
description="Story sample with narrative and two scenario"
id="org.technbolts.jbehave.story.sample2_fr"
autoinsert="true"
name="sample2">A story is a collection of scenarios

${Narrative}
${InOrderTo} communicate effectively to the business some functionality
${AsA} un development team
${IWantTo} use Behaviour-Driven Development

${Scenario} A scenario is a collection of executable steps of different type

${Given} step represents a precondition to an event
${When) step represents the occurrence of the event
${Then} step represents the outcome of the event

${Scenario} Another scenario exploring different combination of events

${Given} a precondition
${When} a negative event occurs
${Then} a the outcome should be captured
</template>
</templates>
38 changes: 38 additions & 0 deletions jbehave_templates/jbehave_templates_fr_FR_Traditional.xml
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<template
context="org.technbolts.jbehave.story"
description="Story sample"
id="org.technbolts.jbehave.story.sample1_fr_FR_Traditional"
autoinsert="true"
name="sample1">${Scenario} un trader n'est pas alerté en-dessous d'un certain seuil

${Given} un stock d'action ${symbol} et un seuil de ${threshold:10.0f}
${When} le stock est vendu à ${value:5.0}
${Then} l'alerte doit être ${status:OFF}
</template>
<template
context="org.technbolts.jbehave.story"
description="Story sample with narrative and two scenario"
id="org.technbolts.jbehave.story.sample2_fr_FR_Traditional"
autoinsert="true"
name="sample2">Un histoire est une collection de scénario

${Narrative}
${InOrderTo} communiquer de manière efficace avec le métier sur des fonctionalités
${AsA} que membre de l'équipe de développement
${IWantTo} utiliser le Behaviour-Driven Development

${Scenario} Un scénario est une collection d'étapes executables de différents types

${Given} que une étape représente une précondition à un événement ou une action
${When} l'étape représentant cet évènement se produit
${Then} cette étape représente le résultat attendu

${Scenario} Un autre scénario explorant différentes combinaison d'évènements.

${Given} une précondition
${When} un évènement négatif se produit
${Then} le résultat attendu doit être capturé
</template>
</templates>
27 changes: 27 additions & 0 deletions jbehave_templates/jbehave_templates_shared.xml
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<template
context="org.technbolts.jbehave.story"
description="Story preamble"
id="org.technbolts.jbehave.story.preamble_shared"
autoinsert="true"
name="preamble">${Narrative}
${InOrderTo} ${inOrderTo}
${AsA} ${asA}
${IWantTo} ${iWantTo}
</template>
<template
context="org.technbolts.jbehave.story"
description="Simple scenario"
id="org.technbolts.jbehave.story.scenario_shared"
autoinsert="true"
name="scenario">
${Scenario} ${scenarioTitle}

${Given} ${given}
${And} ${givenAnd}
${When} ${when}
${And} ${whenAnd}
${Then} ${then}
</template>
</templates>
12 changes: 9 additions & 3 deletions plugin.xml
Expand Up @@ -17,12 +17,18 @@
<extension
point="org.eclipse.ui.editors.templates">
<include
file="jbehave_templates/jbehave_templates.xml">
</include>
file="jbehave_templates/jbehave_templates_shared.xml" />
<include
file="jbehave_templates/jbehave_templates_en.xml" />
<include
file="jbehave_templates/jbehave_templates_fr.xml"/>
<include
file="jbehave_templates/jbehave_templates_fr_FR_Traditional.xml"/>

<contextType
class="org.technbolts.jbehave.eclipse.editors.story.completion.StoryContextType"
id="org.technbolts.jbehave.story"
name="JBehave story">
name="JBehave Templates">
</contextType>
</extension>

Expand Down
30 changes: 30 additions & 0 deletions src/i18n/keywords_fr_FR_Traditional.properties
@@ -0,0 +1,30 @@
Meta=Meta:
MetaProperty=@
Narrative=Narrative\:
InOrderTo=Afin de
AsA=En tant que
IWantTo=Je veux
Scenario=Sc\u00E9nario\:
GivenStories=Etant donn\u00E9 les Histoires\:
ExamplesTable=Exemples\:
ExamplesTableRow=Exemple\:
ExamplesTableHeaderSeparator=|
ExamplesTableValueSeparator=|
ExamplesTableIgnorableSeparator=|--
Given=Etant donn\u00E9
When=Quand
Then=Alors
And=Et
Ignorable=!--
Pending=EN SUSPENS
NotPerformed=NON EX\u00C9CUT\u00C9
Failed=ECHEC
DryRun=EX\u00C9CUTION SIMUL\u00C9E
StoryCancelled=HISTORIE ANNUL\u00C9E
Duration=DUR\u00C9E
OutcomeDescription=D\u00E9scription
OutcomeValue=Valeur
OutcomeMatcher=Matcher
OutcomeVerified=V\u00E9rifi\u00E9
Yes=Oui
No=Non
5 changes: 2 additions & 3 deletions src/org/technbolts/jbehave/eclipse/JBehaveProject.java
Expand Up @@ -56,7 +56,6 @@ public class JBehaveProject {
private ClassScannerPreferences classScannerPreferences;
//
private LocalizedStepSupport localizedStepSupport;
private Locale storyLocale;
//
private AtomicInteger comod = new AtomicInteger();
private volatile int rebuildTick = -1;
Expand Down Expand Up @@ -113,7 +112,7 @@ private void reloadProjectPreferences() {
} catch (BackingStoreException e) {
log.error("Failed to load project preferences", e);
}
storyLocale = LocaleUtils.createLocaleFromCode(projectPreferences.getStoryLanguage(), Locale.ENGLISH);
Locale storyLocale = LocaleUtils.createLocaleFromCode(projectPreferences.getStoryLanguage(), Locale.ENGLISH);
localizedStepSupport.setStoryLocale(storyLocale);
parameterPrefix = projectPreferences.getParameterPrefix();

Expand All @@ -136,7 +135,7 @@ public LocalizedStepSupport getLocalizedStepSupport() {
}

public Locale getLocale() {
return storyLocale;
return getLocalizedStepSupport().getLocale();
}

private C2<IMethod, Container<PotentialStep>> newCallback() {
Expand Down
11 changes: 11 additions & 0 deletions src/org/technbolts/jbehave/eclipse/JBehaveProjectRegistry.java
Expand Up @@ -62,6 +62,17 @@ protected void notifyProjectChanges(IProject project, IJavaElementDelta delta) {
}
}

/**
*
* @param project
* @return
* @see #getOrCreateProject(IProject)
*/
public JBehaveProject getProject(IProject project) {
JBehaveProject cache = projectCache.get(project);
return cache;
}

public JBehaveProject getOrCreateProject(IProject project) {
JBehaveProject cache = projectCache.get(project);
if(cache==null) {
Expand Down
46 changes: 45 additions & 1 deletion src/org/technbolts/jbehave/eclipse/editors/story/StoryView.java
@@ -1,19 +1,33 @@
package org.technbolts.jbehave.eclipse.editors.story;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartReference;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.wb.swt.SWTResourceManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.technbolts.jbehave.eclipse.JBehaveProject;
import org.technbolts.jbehave.eclipse.JBehaveProjectRegistry;

public class StoryView extends ViewPart {

public static final String ID = "org.technbolts.jbehave.eclipse.editors.story.StoryView"; //$NON-NLS-1$

private Logger logger = LoggerFactory.getLogger(StoryView.class);

private Label storylanguagelabel;

public StoryView() {
Expand All @@ -22,6 +36,27 @@ public StoryView() {
@Override
public void init(IViewSite site) throws PartInitException {
super.init(site);
site.getWorkbenchWindow().getSelectionService().addSelectionListener(new ISelectionListener() {
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if(selection.isEmpty() || !(selection instanceof IStructuredSelection))
return;

IStructuredSelection structured = (IStructuredSelection)selection;
Object firstElement = structured.getFirstElement();
if(!(firstElement instanceof IAdaptable))
return;

IAdaptable adaptable = (IAdaptable)firstElement;
IProject project = (IProject) adaptable.getAdapter(IProject.class);
if(project==null) {
logger.warn(">> {} ({})", adaptable, adaptable.getClass());
return;
}
JBehaveProject jbehaveProject = JBehaveProjectRegistry.get().getProject(project);
updateProjectInfos(jbehaveProject);
}
});
site.getPage().addPartListener(new IPartListener2() {

@Override
Expand Down Expand Up @@ -73,7 +108,14 @@ private void changeContent (IWorkbenchPartReference partRef) {
if(!isInterestedBy(partRef))
return;
StoryEditor editorPart = (StoryEditor)partRef.getPart(true);
storylanguagelabel.setText(editorPart.getJBehaveProject().getLocale().toString());
JBehaveProject jBehaveProject = editorPart.getJBehaveProject();
updateProjectInfos(jBehaveProject);
}

protected void updateProjectInfos(JBehaveProject jbehaveProject) {
if(jbehaveProject==null)
return;
storylanguagelabel.setText(jbehaveProject.getLocale().toString());
}

private boolean isInterestedBy(IWorkbenchPartReference partRef) {
Expand All @@ -96,6 +138,8 @@ public void createPartControl(Composite parent) {
{
storylanguagelabel = new Label(container, SWT.NONE);
storylanguagelabel.setText("en");
storylanguagelabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

}

createActions();
Expand Down
@@ -0,0 +1,48 @@
package org.technbolts.jbehave.eclipse.editors.story.completion;

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.templates.DocumentTemplateContext;
import org.eclipse.jface.text.templates.Template;
import org.eclipse.jface.text.templates.TemplateBuffer;
import org.eclipse.jface.text.templates.TemplateContextType;
import org.eclipse.jface.text.templates.TemplateException;
import org.eclipse.jface.text.templates.TemplateTranslator;
import org.technbolts.jbehave.eclipse.JBehaveProject;

public class JBehaveTemplateContext extends DocumentTemplateContext {

private final JBehaveProject project;

public JBehaveTemplateContext(final TemplateContextType contextType,
final JBehaveProject project,
final IDocument document,
final int offset,
final int length) {
super(contextType, document, offset, length);
this.project = project;
}

@Override
public boolean canEvaluate(Template template) {
return true;
}

@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
if (!canEvaluate(template)) {
return null;
}
final TemplateTranslator translator = new TemplateTranslator();
final TemplateBuffer buffer = translator.translate(template);

getContextType().resolve(buffer, this);

return buffer;
}

public JBehaveProject getProject() {
return project;
}

}

0 comments on commit d784e1e

Please sign in to comment.