blob: 6d100d24d55c74b4ffa557c9b6afe769c2cdf5c2 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.karaf.webconsole.core;
import java.util.HashMap;
import java.util.Map;
import org.apache.karaf.webconsole.core.brand.DefaultBrandProvider;
import org.apache.karaf.webconsole.core.dashboard.DashboardPage;
import org.apache.karaf.webconsole.core.internal.WebConsoleApplication;
import org.apache.karaf.webconsole.core.page.LoginPage;
import org.apache.wicket.authorization.UnauthorizedInstantiationException;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.util.tester.FormTester;
import org.apache.wicket.util.tester.WicketTester;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
/**
* Test login operation and role verification.
*/
@RunWith(BlockJUnit4ClassRunner.class)
public class LoginTest {
/**
* Application instance.
*/
private WebApplication application;
@Before
public void setUp() {
application = new WebConsoleApplication();
final Map<String, Object> values = new HashMap<String, Object>();
values.put("brandProvider", new DefaultBrandProvider());
application.addComponentInstantiationListener(new TestInjector(values));
}
@Test
public void testSuccessLogin() throws Exception {
WicketTester tester = new WicketTester(application);
tester.startPage(LoginPage.class);
//tester.debugComponentTrees();
FormTester form = tester.newFormTester("signIn:signInForm");
form.setValue("username", "rootadmin");
form.setValue("password", "admin");
form.submit();
tester.assertNoErrorMessage();
tester.assertRenderedPage(DashboardPage.class);
}
@Test(expected = UnauthorizedInstantiationException.class)
public void testWrongRoleLogin() throws Exception {
WicketTester tester = new WicketTester(application);
tester.startPage(LoginPage.class);
FormTester form = tester.newFormTester("signIn:signInForm");
form.setValue("username", "someuser");
form.setValue("password", "user");
form.submit();
}
}