// Path: fernet-java8/src/test/java/com/macasaet/fernet/example/autofill/Client.java
// public static class Form {
//     public String notificationType;
//     public String firstName;
//     public String lastName;
//     public String emailAddress;
//     public boolean autofilled = false;
// }


import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
import org.junit.Test;
import com.macasaet.fernet.example.autofill.Client.Form;
/**
   Copyright 2017 Carlos Macasaet

   Licensed 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 com.macasaet.fernet.example.autofill;





/**
 * <p>In this example, a website presents a form that requires a user to provide personally-identifying information in
 * order to sign up for various types of notifications. In this scenario, the user may wish to register for multiple
 * notification types. In order to streamline subsequent registrations, we would like to auto-fill the form. However, if
 * the user's computer is compromised, we do not want to allow third-parties to glean the user's personal information.</p>
 * 
 * <p>In this example, the server embeds the user's personal information in a Fernet token. The client is responsible for
 * storing it.</p>
 *
 * <p>Copyright &copy; 2017 Carlos Macasaet.</p>
 *
 * @author Carlos Macasaet
 */
public class AutofillExampleIT {

    private Instant now = Instant.now();
    private Clock clock = new Clock() {

        public Clock withZone(ZoneId zone) {
            return this;
        }

        public Instant instant() {
            return now;
        }

        public ZoneId getZone() {
            return ZoneOffset.UTC;
        }
    };
    private final Server server = new Server(clock);
    private final Client client = new Client(clock, server);

    @Test
    public final void demo() throws Exception {
        // the first time the form is presented, all the information must be provided
// Path: fernet-java8/src/test/java/com/macasaet/fernet/example/autofill/Client.java
// public static class Form {
//     public String notificationType;
//     public String firstName;
//     public String lastName;
//     public String emailAddress;
//     public boolean autofilled = false;
// }


// Path: fernet-java8/src/test/java/com/macasaet/fernet/example/autofill/AutofillExampleIT.java
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
import org.junit.Test;
import com.macasaet.fernet.example.autofill.Client.Form;

/**
   Copyright 2017 Carlos Macasaet

   Licensed 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 com.macasaet.fernet.example.autofill;





/**
 * <p>In this example, a website presents a form that requires a user to provide personally-identifying information in
 * order to sign up for various types of notifications. In this scenario, the user may wish to register for multiple
 * notification types. In order to streamline subsequent registrations, we would like to auto-fill the form. However, if
 * the user's computer is compromised, we do not want to allow third-parties to glean the user's personal information.</p>
 * 
 * <p>In this example, the server embeds the user's personal information in a Fernet token. The client is responsible for
 * storing it.</p>
 *
 * <p>Copyright &copy; 2017 Carlos Macasaet.</p>
 *
 * @author Carlos Macasaet
 */
public class AutofillExampleIT {

    private Instant now = Instant.now();
    private Clock clock = new Clock() {

        public Clock withZone(ZoneId zone) {
            return this;
        }

        public Instant instant() {
            return now;
        }

        public ZoneId getZone() {
            return ZoneOffset.UTC;
        }
    };
    private final Server server = new Server(clock);
    private final Client client = new Client(clock, server);

    @Test
    public final void demo() throws Exception {
        // the first time the form is presented, all the information must be provided
        Form form = client.renderForm();