Example usage for org.apache.ibatis.session SqlSession getMapper

List of usage examples for org.apache.ibatis.session SqlSession getMapper

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession getMapper.

Prototype

<T> T getMapper(Class<T> type);

Source Link

Document

Retrieves a mapper.

Usage

From source file:com.bibisco.test.PropertiesManagerTest.java

License:GNU General Public License

@Test
public void testUpdateProperties() throws ConfigurationException, IOException {

    Map<String, String> lMapProperties = new HashMap<String, String>();
    lMapProperties.put("socialMediaTip", "false");
    lMapProperties.put("locationsdndTip", "false");
    PropertiesManager.getInstance().updateProperties(lMapProperties);

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    Properties lProperties;//  ww w  .  j  ava2  s . com
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        lProperties = lPropertiesMapper.selectByPrimaryKey("socialMediaTip");
    } finally {
        lSqlSession.close();
    }
    Assert.assertEquals(lProperties.getValue(), "false");

    lSqlSession = lSqlSessionFactory.openSession();
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        lProperties = lPropertiesMapper.selectByPrimaryKey("locationsdndTip");
    } finally {
        lSqlSession.close();
    }
    Assert.assertEquals(lProperties.getValue(), "false");
}

From source file:com.bibisco.test.RichTextEditorSettingsManagerTest.java

License:GNU General Public License

@Test
public void testSaveSettings() {

    RichTextEditorSettings lRichTextEditorSettings = new RichTextEditorSettings();
    lRichTextEditorSettings.setFont("arial");
    lRichTextEditorSettings.setSize("small");
    lRichTextEditorSettings.setIndentParagraphEnabled(false);
    lRichTextEditorSettings.setSpellCheckEnabled(false);
    lRichTextEditorSettings.setAutoSaveEnabled(false);
    RichTextEditorSettingsManager.save(lRichTextEditorSettings);

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    Properties lProperties;//from www.  j  a  v  a 2s  .c om
    String lStrFont;
    String lStrFontSize;
    String lStrIndentParagraphEnabled;
    String lStrSpellCheckEnabled;
    String lStrAutoSaveEnabled;
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        lProperties = lPropertiesMapper.selectByPrimaryKey("font");
        lStrFont = lProperties.getValue();
        lProperties = lPropertiesMapper.selectByPrimaryKey("font-size");
        lStrFontSize = lProperties.getValue();
        lProperties = lPropertiesMapper.selectByPrimaryKey("indentParagraphEnabled");
        lStrIndentParagraphEnabled = lProperties.getValue();
        lProperties = lPropertiesMapper.selectByPrimaryKey("spellCheckEnabled");
        lStrSpellCheckEnabled = lProperties.getValue();
        lProperties = lPropertiesMapper.selectByPrimaryKey("autoSaveEnabled");
        lStrAutoSaveEnabled = lProperties.getValue();
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(lStrFont, "arial");
    Assert.assertEquals(lStrFontSize, "small");
    Assert.assertEquals(lStrIndentParagraphEnabled, "false");
    Assert.assertEquals(lStrSpellCheckEnabled, "false");
    Assert.assertEquals(lStrAutoSaveEnabled, "false");
}

From source file:com.bibisco.test.RichTextEditorSettingsManagerTest.java

License:GNU General Public License

@Before
@After//w  ww . j a  v  a  2 s.c  om
public void init() {

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);

        Properties lProperties = new Properties();
        lProperties.setProperty("font");
        lProperties.setValue("courier");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lProperties = new Properties();
        lProperties.setProperty("font-size");
        lProperties.setValue("medium");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lProperties = new Properties();
        lProperties.setProperty("indentParagraphEnabled");
        lProperties.setValue("true");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lProperties = new Properties();
        lProperties.setProperty("spellCheckEnabled");
        lProperties.setValue("true");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lProperties = new Properties();
        lProperties.setProperty("autoSaveEnabled");
        lProperties.setValue("true");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lSqlSession.commit();
    } catch (Throwable t) {
        lSqlSession.rollback();
    } finally {
        lSqlSession.close();
    }

    PropertiesManager.getInstance().reload();
}

From source file:com.bibisco.test.RichTextEditorSettingsManagerTest.java

License:GNU General Public License

@Test
public void testSaveSettingsWithoutIndentParagraphEnabled() {
    RichTextEditorSettings lRichTextEditorSettings = new RichTextEditorSettings();
    lRichTextEditorSettings.setFont("arial");
    lRichTextEditorSettings.setSize("small");
    lRichTextEditorSettings.setIndentParagraphEnabled(false);
    lRichTextEditorSettings.setSpellCheckEnabled(true);
    lRichTextEditorSettings.setAutoSaveEnabled(true);
    RichTextEditorSettingsManager.save(lRichTextEditorSettings);

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    Properties lProperties;//from   w ww . j  a  va  2 s .  co m
    String lStrIndentParagraphEnabled;
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        lProperties = lPropertiesMapper.selectByPrimaryKey("indentParagraphEnabled");
        lStrIndentParagraphEnabled = lProperties.getValue();
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(lStrIndentParagraphEnabled, "false");
}

From source file:com.bibisco.test.RichTextEditorSettingsManagerTest.java

License:GNU General Public License

@Test
public void testSaveSettingsWithoutSpellCheckEnabled() {
    RichTextEditorSettings lRichTextEditorSettings = new RichTextEditorSettings();
    lRichTextEditorSettings.setFont("arial");
    lRichTextEditorSettings.setSize("small");
    lRichTextEditorSettings.setIndentParagraphEnabled(true);
    lRichTextEditorSettings.setSpellCheckEnabled(false);
    lRichTextEditorSettings.setAutoSaveEnabled(true);
    RichTextEditorSettingsManager.save(lRichTextEditorSettings);

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    Properties lProperties;/* www.j  av  a  2  s .  c om*/
    String lStrSpellCheckEnabled;
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        lProperties = lPropertiesMapper.selectByPrimaryKey("spellCheckEnabled");
        lStrSpellCheckEnabled = lProperties.getValue();
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(lStrSpellCheckEnabled, "false");
}

From source file:com.bibisco.test.RichTextEditorSettingsManagerTest.java

License:GNU General Public License

@Test
public void testSaveSettingsWithoutAutoSaveEnabled() {
    RichTextEditorSettings lRichTextEditorSettings = new RichTextEditorSettings();
    lRichTextEditorSettings.setFont("arial");
    lRichTextEditorSettings.setSize("small");
    lRichTextEditorSettings.setIndentParagraphEnabled(true);
    lRichTextEditorSettings.setSpellCheckEnabled(true);
    lRichTextEditorSettings.setAutoSaveEnabled(false);
    RichTextEditorSettingsManager.save(lRichTextEditorSettings);

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    Properties lProperties;//from   w w w .j av  a 2 s  .co m
    String lStrAutoSaveEnabled;
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        lProperties = lPropertiesMapper.selectByPrimaryKey("autoSaveEnabled");
        lStrAutoSaveEnabled = lProperties.getValue();
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(lStrAutoSaveEnabled, "false");
}

From source file:com.bibisco.test.TipManagerTest.java

License:GNU General Public License

@Test
public void testDisableTip() {

    TipManager.disableTip("sceneTip");

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    Properties lProperties;//from   ww  w .j av a  2s.com
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        lProperties = lPropertiesMapper.selectByPrimaryKey("sceneTip");
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(lProperties.getValue(), "false");
}

From source file:com.bibisco.test.TipManagerTest.java

License:GNU General Public License

@Test
public void testDonationTip29DaysFromNow() {

    DateFormat lDateFormat = new SimpleDateFormat(DATE_FORMAT);
    Date lDate29DaysFromNow = DateUtils.addDays(new Date(), -29);

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {//from   w  ww  . j a v a2s . c o  m
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        Properties lProperties = new Properties();
        lProperties.setProperty("donationTip");
        lProperties.setValue(lDateFormat.format(lDate29DaysFromNow));
        lPropertiesMapper.updateByPrimaryKey(lProperties);
        lSqlSession.commit();
    } catch (Throwable t) {
        lSqlSession.rollback();
    } finally {
        lSqlSession.close();
    }
    PropertiesManager.getInstance().reload();
    TipSettings lTipSettings = TipManager.load();
    Assert.assertEquals(lTipSettings.isDonationTip(), false);
}

From source file:com.bibisco.test.TipManagerTest.java

License:GNU General Public License

@Test
public void testDonationTip30DaysFromNow() {

    DateFormat lDateFormat = new SimpleDateFormat(DATE_FORMAT);
    Date lDate29DaysFromNow = DateUtils.addDays(new Date(), -30);

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {//w w w .j  a v  a 2s. com
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        Properties lProperties = new Properties();
        lProperties.setProperty("donationTip");
        lProperties.setValue(lDateFormat.format(lDate29DaysFromNow));
        lPropertiesMapper.updateByPrimaryKey(lProperties);
        lSqlSession.commit();
    } catch (Throwable t) {
        lSqlSession.rollback();
    } finally {
        lSqlSession.close();
    }
    PropertiesManager.getInstance().reload();
    TipSettings lTipSettings = TipManager.load();
    Assert.assertEquals(lTipSettings.isDonationTip(), true);
}

From source file:com.bibisco.test.TipManagerTest.java

License:GNU General Public License

@Before
@After// w  ww. j a  v  a 2  s.  co m
public void init() {

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);

        Properties lProperties = new Properties();
        lProperties.setProperty("sceneTip");
        lProperties.setValue("true");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lProperties = new Properties();
        lProperties.setProperty("donationTip");
        lProperties.setValue("");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lProperties = new Properties();
        lProperties.setProperty("chaptersdndTip");
        lProperties.setValue("true");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lProperties = new Properties();
        lProperties.setProperty("scenesdndTip");
        lProperties.setValue("true");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lProperties = new Properties();
        lProperties.setProperty("locationsdndTip");
        lProperties.setValue("true");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lProperties = new Properties();
        lProperties.setProperty("charactersdndTip");
        lProperties.setValue("true");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lProperties = new Properties();
        lProperties.setProperty("strandsdndTip");
        lProperties.setValue("true");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lProperties = new Properties();
        lProperties.setProperty("socialMediaTip");
        lProperties.setValue("true");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lSqlSession.commit();
    } catch (Throwable t) {
        lSqlSession.rollback();
    } finally {
        lSqlSession.close();
    }

    PropertiesManager.getInstance().reload();
}