////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014, Wotif.com. All rights reserved.
//
// This is unpublished proprietary source code of Wotif.com.
// The copyright notice above does not evidence any actual or intended
// publication of such source code.
//
////////////////////////////////////////////////////////////////////////////////
package com.wotifgroup.logging.logback;

import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.PatternLayout;
import ch.qos.logback.classic.spi.LoggingEvent;
import org.junit.Test;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayOutputStream;

import static org.junit.Assert.assertEquals;

public class CardMaskingLayoutWrappingEncoderTest {

    @Test
    public void maskCardNumbers() throws Exception {
        Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
        LoggerContext loggerContext = rootLogger.getLoggerContext();
        // we are not interested in auto-configuration
        loggerContext.reset();

        final PatternLayout layout = new PatternLayout();
        layout.setContext(loggerContext);
        layout.setPattern("%m");
        layout.start();

        final CardMaskingLayoutWrappingEncoder encoder = new CardMaskingLayoutWrappingEncoder();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        encoder.setContext(loggerContext);
        encoder.setLayout(layout);
        encoder.init(baos);
        encoder.start();

        final LoggingEvent event = new LoggingEvent();

        event.setMessage("Value '378282246310005' is not facet-valid");

        encoder.doEncode(event);

        encoder.stop();
        encoder.close();

        layout.stop();

        assertEquals("Value '378282#####0005' is not facet-valid", baos.toString());
    }

}

@@ -1,90 +1,55 @@
 /
-///////////////////////////////////////////////////////////////////////////////%0A//%0A//
+*%0A * #%25L%0A * Wotif Group Logging Utilities%0A * %25%25%0A *
  Cop
@@ -60,302 +60,603 @@
 ht (
-c
+C
 ) 2014
-,
+ The
  Wotif
-.com. All rights reserved.%0A//%0A// This is unpublished proprietary source code
+ Group%0A * %25%25%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy
  of 
-Wotif.com.%0A// The copyright notice above does not evidence any actual or intended%0A// publication of such source code.%0A//%0A///////////////////////////////////////////////////////////////////////////////
+the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A * #L%25%0A *
 /%0Apa

Fix license header.