MentaTutorials

Compare Revisions

Ignore whitespace Rev 18 → Rev 17

/MentaRefAppWithService/trunk/src/test/java/org/menta/action/LoginActionTest.java
1,12 → 1,10
package org.menta.action;
 
import static org.mentawai.core.Action.ERROR;
import static org.mentawai.core.Action.SUCCESS;
import static org.mentawai.core.Action.*;
import junit.framework.Assert;
 
import org.junit.Test;
import org.menta.AbstractBaseTest;
import org.menta.exception.LoginException.Type;
import org.menta.model.Group;
import org.menta.model.Language;
import org.menta.model.User;
38,25 → 36,41
 
String result, errorId;
User user = new User();
// test only post...
result = login.execute();
Assert.assertEquals(ERROR, result);
input.setProperty("method", "post");
// testing missing username or password...
result = login.execute();
errorId = login.getError("username");
Assert.assertEquals(ERROR, result);
Assert.assertEquals("no_username", errorId);
// test wrong password...
input.setValue("username", "testUser");
input.setValue("password", "wrong_pass");
input.inject(user);
result = login.execute(user);
errorId = login.getError("username");
result = login.execute();
errorId = login.getError("password");
Assert.assertEquals(ERROR, result);
Assert.assertEquals(Type.WRONG_PASSWORD.toString(), errorId);
Assert.assertEquals("bad_password", errorId);
// test success...
input.setValue("password", "abc123");
input.inject(user);
result = login.execute(user);
result = login.execute();
Assert.assertEquals(SUCCESS, result);
}