Search in sources :

Example 1 with MessageSource

use of pl.edu.icm.unity.MessageSource in project unity by unity-idm.

the class StrengthCheckerTest method shouldReturnLowScoreForBadPassword.

@Test
public void shouldReturnLowScoreForBadPassword() throws IOException {
    MessageSource msg = mock(MessageSource.class);
    when(msg.getMessage(eq("feedback.repeat.warning.likeABCABCABC"), any(), any())).thenReturn("ok1");
    when(msg.getMessage(eq("feedback.extra.suggestions.addAnotherWord"), any(), any())).thenReturn("o2k");
    when(msg.getMessage(eq("feedback.repeat.suggestions.avoidRepeatedWords"), any(), any())).thenReturn("ok3");
    StrengthInfo result = StrengthChecker.measure("soso", 10, Locale.ENGLISH, msg);
    assertThat("" + result.scoreNormalized, result.scoreNormalized < 0.15, is(true));
}
Also used : StrengthInfo(pl.edu.icm.unity.stdext.credential.pass.StrengthChecker.StrengthInfo) MessageSource(pl.edu.icm.unity.MessageSource) Test(org.junit.Test)

Example 2 with MessageSource

use of pl.edu.icm.unity.MessageSource in project unity by unity-idm.

the class RegistrationFormTest method shouldValidateLayoutWhenLocalSignupEmbeddedAsButton.

@Test
public void shouldValidateLayoutWhenLocalSignupEmbeddedAsButton() {
    RegistrationForm complete = getRegistrationForm();
    MessageSource msg = Mockito.mock(MessageSource.class);
    RegistrationFormLayouts layouts = new RegistrationFormLayouts();
    layouts.setLocalSignupEmbeddedAsButton(true);
    complete.setFormLayouts(layouts);
    layouts.setPrimaryLayout(complete.getEffectivePrimaryFormLayout(msg));
    layouts.setSecondaryLayout(complete.getEffectiveSecondaryFormLayout(msg));
    layouts.validate(complete);
    Throwable exception = catchThrowable(() -> layouts.validate(complete));
    assertThat(exception).isNull();
}
Also used : RegistrationFormLayouts(pl.edu.icm.unity.types.registration.RegistrationFormLayouts) RegistrationForm(pl.edu.icm.unity.types.registration.RegistrationForm) MessageSource(pl.edu.icm.unity.MessageSource) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 3 with MessageSource

use of pl.edu.icm.unity.MessageSource in project unity by unity-idm.

the class SafePanel method setCaptionFromBundle.

public void setCaptionFromBundle(MessageSource msg, String key, Object... args) {
    Escaper htmlEscaper = HtmlEscapers.htmlEscaper();
    Object[] escapedArgs = Arrays.stream(args).map(arg -> htmlEscaper.escape(arg.toString())).toArray();
    String message = msg.getMessage(key, escapedArgs);
    setCaptionAsHtml(true);
    super.setCaption(message);
}
Also used : Panel(com.vaadin.ui.Panel) Arrays(java.util.Arrays) Escaper(com.google.common.escape.Escaper) HtmlEscapers(com.google.common.html.HtmlEscapers) MessageSource(pl.edu.icm.unity.MessageSource) Component(com.vaadin.ui.Component) Escaper(com.google.common.escape.Escaper)

Example 4 with MessageSource

use of pl.edu.icm.unity.MessageSource in project unity by unity-idm.

the class I18nTextFieldTest method preservesValue.

@Test
public void preservesValue() {
    MessageSource msg = mock(MessageSource.class);
    when(msg.getDefaultLocaleCode()).thenReturn("en");
    Map<String, Locale> locales = new HashMap<>();
    locales.put("english", new Locale("en"));
    locales.put("polski", new Locale("pl"));
    when(msg.getEnabledLocales()).thenReturn(locales);
    I18nTextField tf = new I18nTextField(msg);
    I18nString original = new I18nString("a");
    original.addValue("en", "Value 1");
    original.addValue("pl", "Wartość 1");
    tf.setValue(original);
    I18nString ret = tf.getValue();
    Assert.assertEquals(original, ret);
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) MessageSource(pl.edu.icm.unity.MessageSource) I18nString(pl.edu.icm.unity.types.I18nString) I18nString(pl.edu.icm.unity.types.I18nString) Test(org.junit.Test)

Example 5 with MessageSource

use of pl.edu.icm.unity.MessageSource in project unity by unity-idm.

the class StrengthCheckerTest method shouldReturnMaxScoreForGoodPassword.

@Test
public void shouldReturnMaxScoreForGoodPassword() throws IOException {
    MessageSource msg = mock(MessageSource.class);
    StrengthInfo result = StrengthChecker.measure("horsedonteathorseradishondisk", 10, Locale.ENGLISH, msg);
    assertThat("" + result.scoreNormalized, result.scoreNormalized, is(1.0));
}
Also used : StrengthInfo(pl.edu.icm.unity.stdext.credential.pass.StrengthChecker.StrengthInfo) MessageSource(pl.edu.icm.unity.MessageSource) Test(org.junit.Test)

Aggregations

MessageSource (pl.edu.icm.unity.MessageSource)11 Test (org.junit.Test)7 Locale (java.util.Locale)3 StrengthInfo (pl.edu.icm.unity.stdext.credential.pass.StrengthChecker.StrengthInfo)3 I18nString (pl.edu.icm.unity.types.I18nString)3 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 Escaper (com.google.common.escape.Escaper)1 HtmlEscapers (com.google.common.html.HtmlEscapers)1 StringToIntegerConverter (com.vaadin.data.converter.StringToIntegerConverter)1 IntegerRangeValidator (com.vaadin.data.validator.IntegerRangeValidator)1 Component (com.vaadin.ui.Component)1 Panel (com.vaadin.ui.Panel)1 Binding (groovy.lang.Binding)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 Collectors (java.util.stream.Collectors)1 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1 ApplicationContext (org.springframework.context.ApplicationContext)1